| 54 | } |
| 55 | |
| 56 | FFMS_AudioSource::FFMS_AudioSource(const char *SourceFile, FFMS_Index &Index, int Track, int DelayMode, int FillGaps, double DrcScale) |
| 57 | : DrcScale(DrcScale), LastValidTS(AV_NOPTS_VALUE), SourceFile(SourceFile), ResampleContext{ swr_alloc() }, TrackNumber(Track) { |
| 58 | try { |
| 59 | if (FillGaps < -1 || FillGaps > 1) |
| 60 | throw FFMS_Exception(FFMS_ERROR_INDEX, FFMS_ERROR_INVALID_ARGUMENT, |
| 61 | "Invalid gap fill mode"); |
| 62 | |
| 63 | if (Track < 0 || Track >= static_cast<int>(Index.size())) |
| 64 | throw FFMS_Exception(FFMS_ERROR_INDEX, FFMS_ERROR_INVALID_ARGUMENT, |
| 65 | "Out of bounds track index selected"); |
| 66 | |
| 67 | if (Index[Track].TT != FFMS_TYPE_AUDIO) |
| 68 | throw FFMS_Exception(FFMS_ERROR_INDEX, FFMS_ERROR_INVALID_ARGUMENT, |
| 69 | "Not an audio track"); |
| 70 | |
| 71 | if (Index[Track].empty()) |
| 72 | throw FFMS_Exception(FFMS_ERROR_INDEX, FFMS_ERROR_INVALID_ARGUMENT, |
| 73 | "Audio track contains no audio frames"); |
| 74 | |
| 75 | if (!Index.CompareFileSignature(SourceFile)) |
| 76 | throw FFMS_Exception(FFMS_ERROR_INDEX, FFMS_ERROR_FILE_MISMATCH, |
| 77 | "The index does not match the source file"); |
| 78 | |
| 79 | Frames = Index[Track]; |
| 80 | LAVFOpts = Index.LAVFOpts; |
| 81 | |
| 82 | DecodeFrame = av_frame_alloc(); |
| 83 | if (!DecodeFrame) |
| 84 | throw FFMS_Exception(FFMS_ERROR_DECODING, FFMS_ERROR_ALLOCATION_FAILED, |
| 85 | "Couldn't allocate frame"); |
| 86 | OpenFile(); |
| 87 | |
| 88 | if (FillGaps == 1 || (FillGaps == -1 && (!strcmp(FormatContext->iformat->name, "flv")))) |
| 89 | Frames.FillAudioGaps(); |
| 90 | |
| 91 | if (Frames.back().PTS == Frames.front().PTS) |
| 92 | SeekOffset = -1; |
| 93 | else |
| 94 | SeekOffset = 10; |
| 95 | |
| 96 | Init(Index, DelayMode); |
| 97 | } catch (...) { |
| 98 | Free(); |
| 99 | throw; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | |
| 104 | #define EXCESSIVE_CACHE_SIZE 400 |
nothing calls this directly
no test coverage detected