avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
sampleformat.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <string>
5 
6 #include "averror.h"
7 #include "ffmpeg.h"
8 
9 extern "C" {
10 #include <libavutil/samplefmt.h>
11 }
12 
13 namespace av {
14 
21 class SampleFormat : public PixSampleFmtWrapper<SampleFormat, AVSampleFormat>
22 {
23 public:
24  enum Alignment
25  {
28  };
29 
31  using Parent::Parent;
32 
33  SampleFormat() = default;
34  explicit SampleFormat(const char* name) noexcept;
35  explicit SampleFormat(const std::string& name) noexcept;
36 
37  const char* name(OptionalErrorCode ec = throws()) const;
38 
39  SampleFormat alternativeSampleFormat(bool isPlanar) const noexcept;
40  SampleFormat packedSampleFormat() const noexcept;
41  SampleFormat planarSampleFormat() const noexcept;
42 
43  bool isPlanar() const noexcept;
44 
45  size_t bytesPerSample(OptionalErrorCode ec = throws()) const;
46  size_t bitsPerSample(OptionalErrorCode ec = throws()) const;
47 
48  size_t requiredBufferSize(int nbChannels, int nbSamples, int align, OptionalErrorCode ec = throws()) const;
49  size_t requiredBufferSize(int nbChannels, int nbSamples, int align, int &lineSize, OptionalErrorCode ec = throws()) const;
50 
51  // Static helper methods
52 
53  static size_t requiredBufferSize(SampleFormat fmt, int nbChannels, int nbSamples, int align, OptionalErrorCode ec = throws());
54  static size_t requiredBufferSize(SampleFormat fmt, int nbChannels, int nbSamples, int align, int &lineSize, OptionalErrorCode ec = throws());
55 
56  static void fillArrays(uint8_t **audioData,
57  int *linesize,
58  const uint8_t *buf,
59  int nbChannels,
60  int nbSamples,
61  SampleFormat fmt,
62  int align,
63  OptionalErrorCode ec = throws());
64 
65  static void setSilence(uint8_t **audioData,
66  int offset,
67  int nbSamples,
68  int nbChannels,
69  SampleFormat fmt);
70 
71 #if 0
72  // WARNING: use this function only if required API call expect data allocated with av_alloc() proc families.
73  // You must free allocated data with av_free(&audioData[0]);
74  static void samplesAlloc(uint8_t **audioData,
75  int *linesize,
76  int nbChannels,
77  int nbSamples,
78  SampleFormat fmt,
79  int align,
80  OptionalErrorCode ec = throws());
81 #endif
82 
83 };
84 
85 } // namespace av
86 
PixSampleFmtWrapper
Definition: ffmpeg.h:140
averror.h
ffmpeg.h
av::SampleFormat::planarSampleFormat
SampleFormat planarSampleFormat() const noexcept
Definition: sampleformat.cpp:36
av::SampleFormat::alternativeSampleFormat
SampleFormat alternativeSampleFormat(bool isPlanar) const noexcept
Definition: sampleformat.cpp:26
av::SampleFormat::AlignDefault
@ AlignDefault
Definition: sampleformat.h:26
av::SampleFormat::requiredBufferSize
size_t requiredBufferSize(int nbChannels, int nbSamples, int align, OptionalErrorCode ec=throws()) const
Definition: sampleformat.cpp:63
av::SampleFormat::SampleFormat
SampleFormat()=default
av::SampleFormat::packedSampleFormat
SampleFormat packedSampleFormat() const noexcept
Definition: sampleformat.cpp:31
av::OptionalErrorCode
Definition: averror.h:63
av::SampleFormat::bitsPerSample
size_t bitsPerSample(OptionalErrorCode ec=throws()) const
Definition: sampleformat.cpp:58
av::SampleFormat::setSilence
static void setSilence(uint8_t **audioData, int offset, int nbSamples, int nbChannels, SampleFormat fmt)
Definition: sampleformat.cpp:101
av::SampleFormat::AlignNone
@ AlignNone
Definition: sampleformat.h:27
av
Definition: audioresampler.cpp:8
av::SampleFormat::bytesPerSample
size_t bytesPerSample(OptionalErrorCode ec=throws()) const
Definition: sampleformat.cpp:46
av::SampleFormat::fillArrays
static void fillArrays(uint8_t **audioData, int *linesize, const uint8_t *buf, int nbChannels, int nbSamples, SampleFormat fmt, int align, OptionalErrorCode ec=throws())
Definition: sampleformat.cpp:91
av::throws
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition: averror.h:179
av::SampleFormat::Alignment
Alignment
Definition: sampleformat.h:24
av::SampleFormat::isPlanar
bool isPlanar() const noexcept
Definition: sampleformat.cpp:41
av::SampleFormat::name
const char * name(OptionalErrorCode ec=throws()) const
Definition: sampleformat.cpp:15
av::SampleFormat
The SampleFormat class is a simple proxy class for AVSampleFormat.
Definition: sampleformat.h:21