Audaspace  1.3.0
A high level audio library.
FFMPEGWriter.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2009-2016 Jörg Müller
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 #pragma once
18 
19 #ifdef FFMPEG_PLUGIN
20 #define AUD_BUILD_PLUGIN
21 #endif
22 
30 #include "util/Buffer.h"
31 #include "file/IWriter.h"
32 
33 #include <string>
34 
35 struct AVCodecContext;
36 extern "C" {
37 #include <libavformat/avformat.h>
38 }
39 
41 
46 {
47 private:
51  int m_position;
52 
56  DeviceSpecs m_specs;
57 
61  AVFormatContext* m_formatCtx;
62 
66  AVCodecContext* m_codecCtx;
67 
71  AVStream* m_stream;
72 
76  AVPacket* m_packet;
77 
81  AVFrame* m_frame;
82 
86  Buffer m_input_buffer;
87 
91  Buffer m_deinterleave_buffer;
92 
96  unsigned int m_input_samples;
97 
101  unsigned int m_input_size;
102 
106  bool m_deinterleave;
107 
111  convert_f m_convert;
112 
113  // delete copy constructor and operator=
114  FFMPEGWriter(const FFMPEGWriter&) = delete;
115  FFMPEGWriter& operator=(const FFMPEGWriter&) = delete;
116 
120  AUD_LOCAL void encode();
121 
125  AUD_LOCAL void close();
126 
127 public:
138  FFMPEGWriter(std::string filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate);
139 
143  virtual ~FFMPEGWriter();
144 
145  virtual int getPosition() const;
146  virtual DeviceSpecs getSpecs() const;
147  virtual void write(unsigned int length, sample_t* buffer);
148 };
149 
convert_f
void(* convert_f)(data_t *target, data_t *source, int length)
The function template for functions converting from one sample format to another, having the same par...
Definition: ConverterFunctions.h:35
ConverterFunctions.h
Defines several conversion functions between different sample formats.
FFMPEGWriter::write
virtual void write(unsigned int length, sample_t *buffer)
Request to write the next length samples out into the sink.
IWriter
This class represents a sound sink where audio data can be written to.
Definition: IWriter.h:61
FFMPEGWriter::FFMPEGWriter
FFMPEGWriter(std::string filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate)
Creates a new writer.
DeviceSpecs
Specification of a sound device.
Definition: Specification.h:120
IWriter.h
Defines the IWriter interface as well as Container and Codec types.
FFMPEGWriter
This class writes a sound file via ffmpeg.
Definition: FFMPEGWriter.h:46
AUD_PLUGIN_API
#define AUD_PLUGIN_API
Used for exporting symbols in the shared library.
Definition: Audaspace.h:94
Buffer.h
The Buffer class.
Container
Container
Container formats for writers.
Definition: IWriter.h:31
AUD_LOCAL
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition: Audaspace.h:80
Codec
Codec
Audio codecs for writers.
Definition: IWriter.h:44
Buffer
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality.
Definition: Buffer.h:34
AUD_NAMESPACE_END
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition: Audaspace.h:119
FFMPEGWriter::getPosition
virtual int getPosition() const
Returns how many samples have been written so far.
sample_t
float sample_t
Sample type.(float samples)
Definition: Audaspace.h:126
AUD_NAMESPACE_BEGIN
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
FFMPEGWriter::getSpecs
virtual DeviceSpecs getSpecs() const
Returns the specification of the audio data being written into the sink.
FFMPEGWriter::~FFMPEGWriter
virtual ~FFMPEGWriter()
Destroys the writer and closes the file.