MCPcopy Create free account
hub / github.com/Nevcairiel/LAVFilters / InitDecoder

Method InitDecoder

decoder/LAVVideo/decoders/avcodec.cpp:297–782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

295}
296
297STDMETHODIMP CDecAvcodec::InitDecoder(AVCodecID codec, const CMediaType *pmt, const MediaSideDataFFMpeg *pSideData)
298{
299 DestroyDecoder();
300 DbgLog((LOG_TRACE, 10, L"Initializing ffmpeg for codec %S", avcodec_get_name(codec)));
301
302 BITMAPINFOHEADER *pBMI = nullptr;
303 videoFormatTypeHandler((const BYTE *)pmt->Format(), pmt->FormatType(), &pBMI);
304
305 if (codec == AV_CODEC_ID_AV1 && IsHardwareAccelerator())
306 {
307 m_pAVCodec = avcodec_find_decoder_by_name("av1");
308 }
309 else
310 {
311 m_pAVCodec = avcodec_find_decoder(codec);
312 }
313 CheckPointer(m_pAVCodec, VFW_E_UNSUPPORTED_VIDEO);
314
315 m_pAVCtx = avcodec_alloc_context3(m_pAVCodec);
316 CheckPointer(m_pAVCtx, E_POINTER);
317
318 DWORD dwDecFlags = m_pCallback->GetDecodeFlags();
319
320 // Use parsing for mpeg1/2 at all times, or H264/HEVC when its not from LAV Splitter
321 if (codec == AV_CODEC_ID_MPEG1VIDEO || codec == AV_CODEC_ID_MPEG2VIDEO ||
322 (!(dwDecFlags & LAV_VIDEO_DEC_FLAG_LAVSPLITTER) &&
323 (pmt->subtype == MEDIASUBTYPE_H264 || pmt->subtype == MEDIASUBTYPE_h264 || pmt->subtype == MEDIASUBTYPE_X264 ||
324 pmt->subtype == MEDIASUBTYPE_x264 || pmt->subtype == MEDIASUBTYPE_H264_bis ||
325 pmt->subtype == MEDIASUBTYPE_HEVC || pmt->subtype == MEDIASUBTYPE_H265)))
326 {
327 m_pParser = av_parser_init(codec);
328 }
329
330 LONG biRealWidth = pBMI->biWidth, biRealHeight = pBMI->biHeight;
331 if (pmt->formattype == FORMAT_VideoInfo || pmt->formattype == FORMAT_MPEGVideo)
332 {
333 VIDEOINFOHEADER *vih = (VIDEOINFOHEADER *)pmt->Format();
334 if (vih->rcTarget.right != 0 && vih->rcTarget.bottom != 0)
335 {
336 biRealWidth = vih->rcTarget.right;
337 biRealHeight = vih->rcTarget.bottom;
338 }
339 }
340 else if (pmt->formattype == FORMAT_VideoInfo2 || pmt->formattype == FORMAT_MPEG2Video)
341 {
342 VIDEOINFOHEADER2 *vih2 = (VIDEOINFOHEADER2 *)pmt->Format();
343 if (vih2->rcTarget.right != 0 && vih2->rcTarget.bottom != 0)
344 {
345 biRealWidth = vih2->rcTarget.right;
346 biRealHeight = vih2->rcTarget.bottom;
347 }
348 }
349
350 m_pAVCtx->codec_id = codec;
351 m_pAVCtx->codec_tag = pBMI->biCompression;
352 m_pAVCtx->coded_width = pBMI->biWidth;
353 m_pAVCtx->coded_height = abs(pBMI->biHeight);
354 m_pAVCtx->bits_per_coded_sample = pBMI->biBitCount;

Callers

nothing calls this directly

Calls 9

videoFormatTypeHandlerFunction · 0.85
getExtraDataFunction · 0.85
SUCCEEDEDFunction · 0.85
FormatMethod · 0.80
FormatTypeMethod · 0.80
GetNumThreadsMethod · 0.80
BitSkipMethod · 0.80
BitReadMethod · 0.80
ParseNALsMethod · 0.45

Tested by

no test coverage detected