////////////// // Close file void MatroskaWrapper::Close() { if (file) { mkv_Close(file); file = NULL; fclose(input->fp); delete input; } }
void FFMatroskaVideo::Free(bool CloseCodec) { TCC.reset(); if (MC.ST.fp) { mkv_Close(MF); } if (CloseCodec) avcodec_close(CodecContext); av_freep(&CodecContext); }
FFMatroskaAudio::FFMatroskaAudio(const char *SourceFile, int Track, FFMS_Index &Index, int DelayMode) : FFMS_AudioSource(SourceFile, Index, Track) , TI(NULL) { if (!(MC.ST.fp = ffms_fopen(SourceFile, "rb"))) throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, std::string("Can't open '") + SourceFile + "': " + strerror(errno)); setvbuf(MC.ST.fp, NULL, _IOFBF, CACHESIZE); if (!(MF = mkv_OpenEx(&MC.ST.base, 0, 0, ErrorMessage, sizeof(ErrorMessage)))) throw FFMS_Exception(FFMS_ERROR_PARSER, FFMS_ERROR_FILE_READ, std::string("Can't parse Matroska file: ") + ErrorMessage); TI = mkv_GetTrackInfo(MF, Track); assert(TI); if (TI->CompEnabled) TCC.reset(new TrackCompressionContext(MF, TI, Track)); CodecContext.reset(avcodec_alloc_context3(NULL), DeleteMatroskaCodecContext); assert(CodecContext); AVCodec *Codec = avcodec_find_decoder(MatroskaToFFCodecID(TI->CodecID, TI->CodecPrivate, 0, TI->AV.Audio.BitDepth)); if (!Codec) { mkv_Close(MF); throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, "Audio codec not found"); } InitializeCodecContextFromMatroskaTrackInfo(TI, CodecContext); if (avcodec_open2(CodecContext, Codec, NULL) < 0) { mkv_Close(MF); throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_CODEC, "Could not open audio codec"); } Init(Index, DelayMode); }
FFMatroskaAudio::~FFMatroskaAudio() { TCC.reset(); // cs_Destroy() must be called before mkv_Close() mkv_Close(MF); }