Skip to content

Commit 4b0d3f6

Browse files
committed
pass stream not codecCtx to decoders
1 parent f53962f commit 4b0d3f6

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

jni/libmediaplayer/decoder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
#define TAG "FFMpegIDecoder"
55

6-
IDecoder::IDecoder()
6+
IDecoder::IDecoder(AVStream* stream)
77
{
88
mQueue = new PacketQueue();
9+
mStream = stream;
910
}
1011

1112
IDecoder::~IDecoder()
@@ -58,13 +59,12 @@ int IDecoder::wait()
5859
void IDecoder::stop()
5960
{
6061
mQueue->abort();
61-
__android_log_print(ANDROID_LOG_INFO, TAG, "waiting on end of audio IDecoder");
62+
__android_log_print(ANDROID_LOG_INFO, TAG, "waiting on end of decoder thread");
6263
int ret = -1;
6364
if((ret = wait()) != 0) {
6465
__android_log_print(ANDROID_LOG_ERROR, TAG, "Couldn't cancel audio IDecoder: %i", ret);
6566
return;
6667
}
67-
__android_log_print(ANDROID_LOG_INFO, TAG, "audio IDecoder ended");
6868
}
6969

7070
void* IDecoder::startDecoding(void* ptr)
@@ -74,6 +74,7 @@ void* IDecoder::startDecoding(void* ptr)
7474
decoder->mDecoding = true;
7575
decoder->decode(ptr);
7676
decoder->mDecoding = false;
77+
__android_log_print(ANDROID_LOG_INFO, TAG, "decoder thread ended");
7778
}
7879

7980
bool IDecoder::prepare(const char *err)

jni/libmediaplayer/decoder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern "C" {
1515
class IDecoder
1616
{
1717
public:
18-
IDecoder();
18+
IDecoder(AVStream* stream);
1919
~IDecoder();
2020

2121
bool start(const char* err);
@@ -27,7 +27,8 @@ class IDecoder
2727

2828
protected:
2929
PacketQueue* mQueue;
30-
AVCodecContext* mCodecCtx;
30+
AVStream* mStream;
31+
AVCodecContext* mCodecCtx;
3132
bool mDecoding;
3233
pthread_t mThread;
3334

jni/libmediaplayer/decoder_audio.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55

66
#define TAG "FFMpegAudioDecoder"
77

8-
DecoderAudio::DecoderAudio(AVCodecContext* codec_ctx,
9-
struct DecoderAudioConfig* config)
8+
DecoderAudio::DecoderAudio(AVStream* stream,
9+
struct DecoderAudioConfig* config) : IDecoder(stream)
1010
{
11-
mCodecCtx = codec_ctx;
1211
mConfig = config;
1312
}
1413

@@ -42,7 +41,7 @@ bool DecoderAudio::prepare(const char *err)
4241
bool DecoderAudio::process(AVPacket *packet)
4342
{
4443
int size = mSamplesSize;
45-
int len = avcodec_decode_audio3(mCodecCtx, mSamples, &size, packet);
44+
int len = avcodec_decode_audio3(mStream->codec, mSamples, &size, packet);
4645
if(Output::AudioDriver_write(mSamples, size) <= 0) {
4746
return false;
4847
}

jni/libmediaplayer/decoder_audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct DecoderAudioConfig
1414
class DecoderAudio : public IDecoder
1515
{
1616
public:
17-
DecoderAudio(AVCodecContext* codec_ctx,
17+
DecoderAudio(AVStream* stream,
1818
struct DecoderAudioConfig* config);
1919

2020
~DecoderAudio();

jni/libmediaplayer/decoder_video.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ extern "C" {
1010
#define TAG "FFMpegVideoDecoder"
1111

1212
DecoderVideo::DecoderVideo(AVCodecContext* codec_ctx,
13-
struct DecoderVideoConfig* config)
13+
struct DecoderVideoConfig* config) : IDecoder(NULL)
1414
{
15-
mCodecCtx = codec_ctx;
15+
mCodecCtx = codec_ctx;
1616
mConfig = config;
1717
}
1818

jni/libmediaplayer/mediaplayer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ void MediaPlayer::decodeMovie(void* ptr)
361361
cfg.sampleRate = mFFmpegStorage.audio.codec_ctx->sample_rate;
362362
cfg.format = PCM_16_BIT;
363363
cfg.channels = (mFFmpegStorage.audio.codec_ctx->channels == 2) ? CHANNEL_OUT_STEREO : CHANNEL_OUT_MONO;
364-
mDecoderAudio = new DecoderAudio(mFFmpegStorage.audio.codec_ctx, &cfg);
364+
AVStream* stream = mFFmpegStorage.pFormatCtx->streams[mFFmpegStorage.audio.stream];
365+
mDecoderAudio = new DecoderAudio(stream, &cfg);
365366
if(!mDecoderAudio->startAsync(err))
366367
{
367368
__android_log_print(ANDROID_LOG_INFO, TAG, "Couldn't start audio decoder: %s", err);

0 commit comments

Comments
 (0)