diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 26c02b3240..f6efde4437 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -181,6 +181,21 @@ static int setup_format(sh_audio_t *sh_audio, return 0; } +static void set_from_wf(AVCodecContext *avctx, WAVEFORMATEX *wf) +{ + avctx->channels = wf->nChannels; + avctx->sample_rate = wf->nSamplesPerSec; + avctx->bit_rate = wf->nAvgBytesPerSec * 8; + avctx->block_align = wf->nBlockAlign; + avctx->bits_per_coded_sample = wf->wBitsPerSample; + + if (wf->cbSize > 0) { + avctx->extradata = av_mallocz(wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE); + avctx->extradata_size = wf->cbSize; + memcpy(avctx->extradata, wf + 1, avctx->extradata_size); + } +} + static int init(sh_audio_t *sh_audio, const char *decoder) { struct MPOpts *opts = sh_audio->opts; @@ -212,13 +227,7 @@ static int init(sh_audio_t *sh_audio, const char *decoder) AV_OPT_SEARCH_CHILDREN); lavc_context->sample_rate = sh_audio->samplerate; lavc_context->bit_rate = sh_audio->i_bps * 8; - if (sh_audio->wf) { - lavc_context->channels = sh_audio->wf->nChannels; - lavc_context->sample_rate = sh_audio->wf->nSamplesPerSec; - lavc_context->bit_rate = sh_audio->wf->nAvgBytesPerSec * 8; - lavc_context->block_align = sh_audio->wf->nBlockAlign; - lavc_context->bits_per_coded_sample = sh_audio->wf->wBitsPerSample; - } + lavc_context->request_channels = opts->audio_output_channels; lavc_context->codec_tag = sh_audio->format; //FOURCC if (sh_audio->gsh->lavf_codec_tag) @@ -226,13 +235,8 @@ static int init(sh_audio_t *sh_audio, const char *decoder) lavc_context->codec_type = AVMEDIA_TYPE_AUDIO; lavc_context->codec_id = lavc_codec->id; // not sure if required, imho not --A'rpi - /* alloc extra data */ - if (sh_audio->wf && sh_audio->wf->cbSize > 0) { - lavc_context->extradata = av_mallocz(sh_audio->wf->cbSize + FF_INPUT_BUFFER_PADDING_SIZE); - lavc_context->extradata_size = sh_audio->wf->cbSize; - memcpy(lavc_context->extradata, sh_audio->wf + 1, - lavc_context->extradata_size); - } + if (sh_audio->wf) + set_from_wf(lavc_context, sh_audio->wf); // for QDM2 if (sh_audio->codecdata_len && sh_audio->codecdata && @@ -253,16 +257,6 @@ static int init(sh_audio_t *sh_audio, const char *decoder) mp_msg(MSGT_DECAUDIO, MSGL_V, "INFO: libavcodec \"%s\" init OK!\n", lavc_codec->name); - if (sh_audio->wf && sh_audio->format == 0x3343414D) { - // MACE 3:1 - sh_audio->ds->ss_div = 2 * 3; // 1 samples/packet - sh_audio->ds->ss_mul = 2 * sh_audio->wf->nChannels; // 1 byte*ch/packet - } else if (sh_audio->wf && sh_audio->format == 0x3643414D) { - // MACE 6:1 - sh_audio->ds->ss_div = 2 * 6; // 1 samples/packet - sh_audio->ds->ss_mul = 2 * sh_audio->wf->nChannels; // 1 byte*ch/packet - } - // Decode at least 1 byte: (to get header filled) for (int tries = 0;;) { int x = decode_audio(sh_audio, sh_audio->a_buffer, 1, diff --git a/demux/demux.h b/demux/demux.h index c1e6c3be1c..621df5efcb 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -131,8 +131,6 @@ typedef struct demux_stream { // ---- asf ----- struct demux_packet *asf_packet; // read asf fragments here int asf_seq; -// ---- mov ----- - unsigned int ss_mul, ss_div; // ---- stream header ---- void *sh; // points to sh_audio or sh_video } demux_stream_t; diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 79466460d8..7ae063777a 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -42,7 +42,6 @@ #include "core/bstr.h" #include "stream/stream.h" -#include "aviprint.h" #include "demux.h" #include "stheader.h" #include "core/m_option.h" @@ -371,18 +370,6 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) if (codec->extradata_size) memcpy(wf + 1, codec->extradata, codec->extradata_size); sh_audio->wf = wf; - sh_audio->audio.dwSampleSize = codec->block_align; - if (codec->frame_size && codec->sample_rate) { - sh_audio->audio.dwScale = codec->frame_size; - sh_audio->audio.dwRate = codec->sample_rate; - } else { - sh_audio->audio.dwScale = codec->block_align ? codec->block_align * 8 : 8; - sh_audio->audio.dwRate = codec->bit_rate; - } - int g = av_gcd(sh_audio->audio.dwScale, sh_audio->audio.dwRate); - sh_audio->audio.dwScale /= g; - sh_audio->audio.dwRate /= g; -// printf("sca:%d rat:%d fs:%d sr:%d ba:%d\n", sh_audio->audio.dwScale, sh_audio->audio.dwRate, codec->frame_size, codec->sample_rate, codec->block_align); sh_audio->ds = demuxer->audio; sh_audio->format = codec->codec_tag; sh_audio->channels = codec->channels; @@ -396,8 +383,6 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) sh_audio->format = 0x7; break; } - if (mp_msg_test(MSGT_HEADER, MSGL_V)) - print_wave_header(sh_audio->wf, MSGL_V); st->discard = AVDISCARD_ALL; priv->audio_streams++; break; @@ -440,13 +425,6 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) sh_video->bih = bih; sh_video->disp_w = codec->width; sh_video->disp_h = codec->height; - if (st->time_base.den) { /* if container has time_base, use that */ - sh_video->video.dwRate = st->time_base.den; - sh_video->video.dwScale = st->time_base.num; - } else { - sh_video->video.dwRate = codec->time_base.den; - sh_video->video.dwScale = codec->time_base.num; - } /* Try to make up some frame rate value, even if it's not reliable. * FPS information is needed to support subtitle formats which base * timing on frame numbers. @@ -479,8 +457,6 @@ static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) sh_video->ds = demuxer->video; if (codec->extradata_size) memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size); - if ( mp_msg_test(MSGT_HEADER, MSGL_V)) - print_video_header(sh_video->bih, MSGL_V); if (demuxer->video->id != priv->video_streams && demuxer->video->id != -1) st->discard = AVDISCARD_ALL; diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index 77fb800994..9801361cb2 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -180,6 +180,64 @@ static int init(sh_video_t *sh, const char *decoder) return 1; } +static void set_from_bih(AVCodecContext *avctx, uint32_t format, + BITMAPINFOHEADER *bih) +{ + + switch (format) { + case mmioFOURCC('S','V','Q','3'): + case mmioFOURCC('A','V','R','n'): + case mmioFOURCC('M','J','P','G'): + /* AVRn stores huffman table in AVI header */ + /* Pegasus MJPEG stores it also in AVI header, but it uses the common + * MJPG fourcc :( */ + if (bih->biSize <= sizeof(*bih)) + break; + av_opt_set_int(avctx, "extern_huff", 1, AV_OPT_SEARCH_CHILDREN); + avctx->extradata_size = bih->biSize - sizeof(*bih); + avctx->extradata = av_mallocz(avctx->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, bih + 1, avctx->extradata_size); + break; + + case mmioFOURCC('R','V','1','0'): + case mmioFOURCC('R','V','1','3'): + case mmioFOURCC('R','V','2','0'): + case mmioFOURCC('R','V','3','0'): + case mmioFOURCC('R','V','4','0'): + if (bih->biSize < sizeof(*bih) + 8) { + // only 1 packet per frame & sub_id from fourcc + avctx->extradata_size = 8; + avctx->extradata = av_mallocz(avctx->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + ((uint32_t *)avctx->extradata)[0] = 0; + ((uint32_t *)avctx->extradata)[1] = + format == mmioFOURCC('R','V','1','3') ? + 0x10003001 : 0x10000000; + } else { + // has extra slice header (demux_rm or rm->avi streamcopy) + avctx->extradata_size = bih->biSize - sizeof(*bih); + avctx->extradata = av_mallocz(avctx->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, bih + 1, avctx->extradata_size); + } + break; + + default: + if (bih->biSize <= sizeof(*bih)) + break; + avctx->extradata_size = bih->biSize - sizeof(*bih); + avctx->extradata = av_mallocz(avctx->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, bih + 1, avctx->extradata_size); + break; + } + + avctx->bits_per_coded_sample = bih->biBitCount; + avctx->coded_width = bih->biWidth; + avctx->coded_height = bih->biHeight; +} + static int init_avctx(sh_video_t *sh, const char *decoder, struct hwdec *hwdec) { vd_ffmpeg_ctx *ctx = sh->context; @@ -239,8 +297,8 @@ static int init_avctx(sh_video_t *sh, const char *decoder, struct hwdec *hwdec) avctx->flags |= lavc_param->bitexact; - avctx->coded_width = sh->bih ? sh->bih->biWidth : sh->disp_w; - avctx->coded_height = sh->bih ? sh->bih->biHeight : sh->disp_h; + avctx->coded_width = sh->disp_w; + avctx->coded_height = sh->disp_h; avctx->workaround_bugs = lavc_param->workaround_bugs; if (lavc_param->gray) avctx->flags |= CODEC_FLAG_GRAY; @@ -274,59 +332,8 @@ static int init_avctx(sh_video_t *sh, const char *decoder, struct hwdec *hwdec) // Do this after the above avopt handling in case it changes values ctx->skip_frame = avctx->skip_frame; - mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, - "libavcodec.size: %d x %d\n", avctx->width, avctx->height); - switch (sh->format) { - case mmioFOURCC('S','V','Q','3'): - case mmioFOURCC('A','V','R','n'): - case mmioFOURCC('M','J','P','G'): - /* AVRn stores huffman table in AVI header */ - /* Pegasus MJPEG stores it also in AVI header, but it uses the common - * MJPG fourcc :( */ - if (!sh->bih || sh->bih->biSize <= sizeof(*sh->bih)) - break; - av_opt_set_int(avctx, "extern_huff", 1, AV_OPT_SEARCH_CHILDREN); - avctx->extradata_size = sh->bih->biSize - sizeof(*sh->bih); - avctx->extradata = av_mallocz(avctx->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, sh->bih + 1, avctx->extradata_size); - break; - - case mmioFOURCC('R','V','1','0'): - case mmioFOURCC('R','V','1','3'): - case mmioFOURCC('R','V','2','0'): - case mmioFOURCC('R','V','3','0'): - case mmioFOURCC('R','V','4','0'): - if (sh->bih->biSize < sizeof(*sh->bih) + 8) { - // only 1 packet per frame & sub_id from fourcc - avctx->extradata_size = 8; - avctx->extradata = av_mallocz(avctx->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - ((uint32_t *)avctx->extradata)[0] = 0; - ((uint32_t *)avctx->extradata)[1] = - sh->format == mmioFOURCC('R','V','1','3') ? - 0x10003001 : 0x10000000; - } else { - // has extra slice header (demux_rm or rm->avi streamcopy) - avctx->extradata_size = sh->bih->biSize - sizeof(*sh->bih); - avctx->extradata = av_mallocz(avctx->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, sh->bih + 1, avctx->extradata_size); - } - break; - - default: - if (!sh->bih || sh->bih->biSize <= sizeof(*sh->bih)) - break; - avctx->extradata_size = sh->bih->biSize - sizeof(*sh->bih); - avctx->extradata = av_mallocz(avctx->extradata_size + - FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, sh->bih + 1, avctx->extradata_size); - break; - } - if (sh->bih) - avctx->bits_per_coded_sample = sh->bih->biBitCount; + set_from_bih(avctx, sh->format, sh->bih); if (mp_rawvideo && sh->format >= IMGFMT_START && sh->format < IMGFMT_END) { avctx->pix_fmt = imgfmt2pixfmt(sh->format);