|
| 1 | +#include "codecparameters.h" |
| 2 | +#include "codeccontext.h" |
| 3 | + |
| 4 | +namespace av { |
| 5 | + |
| 6 | +CodecParametersView::CodecParametersView(AVCodecParameters *codecpar) |
| 7 | + : FFWrapperPtr<AVCodecParameters>(codecpar) |
| 8 | +{ |
| 9 | +} |
| 10 | + |
| 11 | +bool CodecParametersView::isValid() const |
| 12 | +{ |
| 13 | + return !isNull(); |
| 14 | +} |
| 15 | + |
| 16 | +void CodecParametersView::copyFrom(CodecParametersView src, OptionalErrorCode ec) |
| 17 | +{ |
| 18 | + clear_if(ec); |
| 19 | + |
| 20 | + if (!m_raw) { |
| 21 | + throws_if(ec, Errors::Unallocated); |
| 22 | + return; |
| 23 | + } |
| 24 | + |
| 25 | + if (!src.m_raw) { |
| 26 | + throws_if(ec, Errors::Unallocated); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + auto const ret = avcodec_parameters_copy(m_raw, src.m_raw); |
| 31 | + if (ret) { |
| 32 | + throws_if(ec, ret, ffmpeg_category()); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +void CodecParametersView::copyTo(CodecParametersView dst, OptionalErrorCode ec) const |
| 37 | +{ |
| 38 | + clear_if(ec); |
| 39 | + |
| 40 | + if (!m_raw) { |
| 41 | + throws_if(ec, Errors::Unallocated); |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + if (!dst.m_raw) { |
| 46 | + throws_if(ec, Errors::Unallocated); |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + auto const ret = avcodec_parameters_copy(dst.m_raw, m_raw); |
| 51 | + if (ret) { |
| 52 | + throws_if(ec, ret, ffmpeg_category()); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +void CodecParametersView::copyFrom(const CodecContext2 &src, OptionalErrorCode ec) |
| 57 | +{ |
| 58 | + clear_if(ec); |
| 59 | + |
| 60 | + if (!m_raw) { |
| 61 | + throws_if(ec, Errors::Unallocated); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + if (!src.raw()) { |
| 66 | + throws_if(ec, Errors::Unallocated); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + auto const ret = avcodec_parameters_from_context(m_raw, src.raw()); |
| 71 | + if (ret) { |
| 72 | + throws_if(ec, ret, ffmpeg_category()); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +void CodecParametersView::copyTo(CodecContext2 &dst, OptionalErrorCode ec) const |
| 77 | +{ |
| 78 | + clear_if(ec); |
| 79 | + |
| 80 | + if (!m_raw) { |
| 81 | + throws_if(ec, Errors::Unallocated); |
| 82 | + return; |
| 83 | + } |
| 84 | + |
| 85 | + if (!dst.raw()) { |
| 86 | + throws_if(ec, Errors::Unallocated); |
| 87 | + return; |
| 88 | + } |
| 89 | + |
| 90 | + auto const ret = avcodec_parameters_to_context(dst.raw(), m_raw); |
| 91 | + if (ret) { |
| 92 | + throws_if(ec, ret, ffmpeg_category()); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +int CodecParametersView::getAudioFrameDuration(int frame_bytes) const |
| 97 | +{ |
| 98 | + if (!m_raw) |
| 99 | + return 0; |
| 100 | + return av_get_audio_frame_duration2(const_cast<AVCodecParameters*>(m_raw), frame_bytes); |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +CodecParameters::CodecParameters() |
| 106 | + : CodecParametersView(avcodec_parameters_alloc()) |
| 107 | +{ |
| 108 | +} |
| 109 | + |
| 110 | +CodecParameters::~CodecParameters() |
| 111 | +{ |
| 112 | + avcodec_parameters_free(&m_raw); |
| 113 | +} |
| 114 | + |
| 115 | +} // namespace av |
0 commit comments