Skip to content

Commit

Permalink
Properly shutdown and release the MediaCodec resources when destroyin…
Browse files Browse the repository at this point in the history
…g a MediaCodecDelegate instance.

Origin: vendor
Forwarded: no

Signed-off-by: Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
  • Loading branch information
Jim Hodapp authored and Ricardo Salveti de Araujo committed Dec 23, 2013
1 parent fdc56ef commit 20f3ab0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions compat/media/media_codec_layer.cpp
Expand Up @@ -188,18 +188,20 @@ void media_codec_delegate_destroy(MediaCodecDelegate delegate)

_MediaCodecDelegate *d = get_internal_delegate(delegate);
if (d == NULL)
{
ALOGE("d == NULL, cannot destroy MediaCodecDelegate instance");
return;
}

if (d->refcount)
return;

d->media_codec->stop();
d->looper->stop();
ALOGI("Releasing media_codec");
d->media_codec->release();
ALOGI("Stopping looper");
d->looper->stop();

d->looper.clear();
d->media_codec.clear();
ALOGI("Setting refcount = 0");
d->refcount = 0;

ALOGI("Deleting the MediaCodecDelegate instance");
delete d;
}

Expand All @@ -220,10 +222,15 @@ void media_codec_delegate_unref(MediaCodecDelegate delegate)

_MediaCodecDelegate *d = get_internal_delegate(delegate);
if (d == NULL)
{
ALOGE("d == NULL, cannot unref MediaCodecDelegate instance");
return;
}

if (d->refcount)
if (d->refcount > 1)
d->refcount--;
else
media_codec_delegate_destroy (delegate);
}

#ifdef SIMPLE_PLAYER
Expand Down

0 comments on commit 20f3ab0

Please sign in to comment.