AvTranscoder  0.9.4
C++APIforLibav/FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AudioFrame.hpp
Go to the documentation of this file.
1 #ifndef _AV_TRANSCODER_FRAME_AUDIO_FRAME_HPP_
2 #define _AV_TRANSCODER_FRAME_AUDIO_FRAME_HPP_
3 
4 #include "Frame.hpp"
6 
7 namespace avtranscoder
8 {
9 
10 /**
11  * @brief Description to create an audio frame.
12  * This corresponds to the number of samples, which corresponds to one video frame.
13  */
14 struct AvExport AudioFrameDesc
15 {
16 public:
17  AudioFrameDesc(const size_t sampleRate = 0, const size_t channels = 0,
18  const AVSampleFormat sampleFormat = AV_SAMPLE_FMT_NONE);
19  AudioFrameDesc(const size_t sampleRate, const size_t channels, const std::string& sampleFormatName);
20 
21  /**
22  * @brief Set the attributes from the given profile.
23  * @see Profile
24  */
25  void setParameters(const ProfileLoader::Profile& profile);
26 
27 public:
28  size_t _sampleRate;
29  size_t _nbChannels;
30  AVSampleFormat _sampleFormat;
31 };
32 
33 /**
34  * @brief This class describes decoded audio data.
35  */
36 class AvExport AudioFrame : public Frame
37 {
38 public:
39  /**
40  * @note Allocated data will be initialized to silence.
41  */
42  AudioFrame(const AudioFrameDesc& ref);
43  AudioFrame(const Frame& otherFrame);
44 
45  size_t getSampleRate() const { return av_frame_get_sample_rate(_frame); }
46  size_t getNbChannels() const { return av_frame_get_channels(_frame); }
47  size_t getChannelLayout() const { return av_frame_get_channel_layout(_frame); }
48  AVSampleFormat getSampleFormat() const { return static_cast<AVSampleFormat>(_frame->format); }
49  size_t getNbSamplesPerChannel() const { return _frame->nb_samples; }
50  AudioFrameDesc desc() const { return AudioFrameDesc(getSampleRate(), getNbChannels(), getSampleFormat()); }
51 
52  size_t getSize() const; ///< in bytes
53 
54  void setNbSamplesPerChannel(const size_t nbSamples) { _frame->nb_samples = nbSamples; }
55 
56  /**
57  * @brief Assign the given value to all the data of the audio frame.
58  */
59  void assign(const unsigned char value);
60 
61  /**
62  * @brief Assign the given ptr of data to the data of the audio frame.
63  * @warning the given ptr should have the size of the audio frame..
64  * @see getSize
65  */
66  void assign(const unsigned char* ptrValue);
67 
68 private:
69  /**
70  * @brief Allocate the audio buffer of the frame.
71  */
72  void allocateAVSample(const AudioFrameDesc& ref);
73 
74  /**
75  * @note To allocate new audio buffer if needed.
76  * @see allocateAVSample
77  */
78  friend class AudioGenerator;
79 };
80 }
81 
82 #endif
size_t getChannelLayout() const
Definition: AudioFrame.hpp:47
AudioFrameDesc desc() const
Definition: AudioFrame.hpp:50
AVSampleFormat getSampleFormat() const
Definition: AudioFrame.hpp:48
std::map< std::string, std::string > Profile
void setNbSamplesPerChannel(const size_t nbSamples)
Definition: AudioFrame.hpp:54
AVSampleFormat _sampleFormat
Definition: AudioFrame.hpp:30
Description to create an audio frame. This corresponds to the number of samples, which corresponds to...
Definition: AudioFrame.hpp:14
size_t getSampleRate() const
Definition: AudioFrame.hpp:45
size_t getNbChannels() const
Definition: AudioFrame.hpp:46
This class describes decoded audio data.
Definition: AudioFrame.hpp:36
This class describes decoded (raw) audio or video data.
Definition: Frame.hpp:16
size_t getNbSamplesPerChannel() const
Definition: AudioFrame.hpp:49