Skip to content

Commit

Permalink
add support for audio decoder async and sync
Browse files Browse the repository at this point in the history
  • Loading branch information
havlenapetr committed Jul 30, 2010
1 parent 53ff5b7 commit 11b97ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions jni/libmediaplayer/decoder_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ DecoderAudio::~DecoderAudio()
}

bool DecoderAudio::start(const char* err)
{
if(!prepare(err))
{
return false;
}
return decode(NULL);
}

bool DecoderAudio::startAsync(const char* err)
{
if(!prepare(err))
{
Expand Down Expand Up @@ -91,7 +100,7 @@ bool DecoderAudio::process(AVPacket *packet)
return true;
}

void DecoderAudio::decode(void* ptr)
bool DecoderAudio::decode(void* ptr)
{
AVPacket pPacket;

Expand All @@ -103,12 +112,12 @@ void DecoderAudio::decode(void* ptr)
if(mQueue->get(&pPacket, true) < 0)
{
mDecoding = false;
continue;
return false;
}
if(!process(&pPacket))
{
mDecoding = false;
continue;
return false;
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&pPacket);
Expand All @@ -120,4 +129,5 @@ void DecoderAudio::decode(void* ptr)

// Free audio samples buffer
av_free(mSamples);
return true;
}
3 changes: 2 additions & 1 deletion jni/libmediaplayer/decoder_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DecoderAudio
~DecoderAudio();

bool start(const char* err);
bool startAsync(const char* err);
void stop();

private:
Expand All @@ -35,7 +36,7 @@ class DecoderAudio
int mSamplesSize;

bool prepare(const char *err);
void decode(void* ptr);
bool decode(void* ptr);
bool process(AVPacket *packet);
static void* startDecoding(void* ptr);
};
Expand Down

0 comments on commit 11b97ef

Please sign in to comment.