mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
flvdec: Add param change side data if the sample rate or channels have changed
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
3e79c2adb1
commit
2215c39e94
@ -43,6 +43,8 @@ typedef struct {
|
|||||||
int wrong_dts; ///< wrong dts due to negative cts
|
int wrong_dts; ///< wrong dts due to negative cts
|
||||||
uint8_t *new_extradata[2];
|
uint8_t *new_extradata[2];
|
||||||
int new_extradata_size[2];
|
int new_extradata_size[2];
|
||||||
|
int last_sample_rate;
|
||||||
|
int last_channels;
|
||||||
} FLVContext;
|
} FLVContext;
|
||||||
|
|
||||||
static int flv_probe(AVProbeData *p)
|
static int flv_probe(AVProbeData *p)
|
||||||
@ -56,8 +58,7 @@ static int flv_probe(AVProbeData *p)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) {
|
static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecContext *acodec, int flv_codecid) {
|
||||||
AVCodecContext *acodec = astream->codec;
|
|
||||||
switch(flv_codecid) {
|
switch(flv_codecid) {
|
||||||
//no distinction between S16 and S8 PCM codec flags
|
//no distinction between S16 and S8 PCM codec flags
|
||||||
case FLV_CODECID_PCM:
|
case FLV_CODECID_PCM:
|
||||||
@ -440,6 +441,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
int ret, i, type, size, flags, is_audio;
|
int ret, i, type, size, flags, is_audio;
|
||||||
int64_t next, pos;
|
int64_t next, pos;
|
||||||
int64_t dts, pts = AV_NOPTS_VALUE;
|
int64_t dts, pts = AV_NOPTS_VALUE;
|
||||||
|
int sample_rate, channels;
|
||||||
AVStream *st = NULL;
|
AVStream *st = NULL;
|
||||||
|
|
||||||
for(;;avio_skip(s->pb, 4)){ /* pkt size is repeated at end. skip it */
|
for(;;avio_skip(s->pb, 4)){ /* pkt size is repeated at end. skip it */
|
||||||
@ -524,13 +526,24 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(is_audio){
|
if(is_audio){
|
||||||
|
int bits_per_coded_sample;
|
||||||
|
channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
|
||||||
|
sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3);
|
||||||
|
bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
|
||||||
if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) {
|
if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) {
|
||||||
st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;
|
st->codec->channels = channels;
|
||||||
st->codec->sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3);
|
st->codec->sample_rate = sample_rate;
|
||||||
st->codec->bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8;
|
st->codec->bits_per_coded_sample = bits_per_coded_sample;
|
||||||
}
|
}
|
||||||
if(!st->codec->codec_id){
|
if(!st->codec->codec_id){
|
||||||
flv_set_audio_codec(s, st, flags & FLV_AUDIO_CODECID_MASK);
|
flv_set_audio_codec(s, st, st->codec, flags & FLV_AUDIO_CODECID_MASK);
|
||||||
|
flv->last_sample_rate = st->codec->sample_rate;
|
||||||
|
flv->last_channels = st->codec->channels;
|
||||||
|
} else {
|
||||||
|
AVCodecContext ctx;
|
||||||
|
ctx.sample_rate = sample_rate;
|
||||||
|
flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK);
|
||||||
|
sample_rate = ctx.sample_rate;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK);
|
size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK);
|
||||||
@ -603,6 +616,12 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||||||
flv->new_extradata_size[is_audio] = 0;
|
flv->new_extradata_size[is_audio] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_audio && (sample_rate != flv->last_sample_rate ||
|
||||||
|
channels != flv->last_channels)) {
|
||||||
|
flv->last_sample_rate = sample_rate;
|
||||||
|
flv->last_channels = channels;
|
||||||
|
ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))
|
if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY))
|
||||||
pkt->flags |= AV_PKT_FLAG_KEY;
|
pkt->flags |= AV_PKT_FLAG_KEY;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user