Audaspace  1.3.0
A high level audio library.
FFMPEGReader.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 "IReader.h"
31 #include "util/Buffer.h"
32 
33 #include <string>
34 #include <memory>
35 
36 struct AVCodecContext;
37 extern "C" {
38 #include <libavformat/avformat.h>
39 }
40 
42 
50 {
51 private:
55  int m_position;
56 
60  DeviceSpecs m_specs;
61 
65  Buffer m_pkgbuf;
66 
70  int m_pkgbuf_left;
71 
75  AVFormatContext* m_formatCtx;
76 
80  AVCodecContext* m_codecCtx;
81 
85  AVIOContext* m_aviocontext;
86 
90  int m_stream;
91 
95  convert_f m_convert;
96 
100  std::shared_ptr<Buffer> m_membuffer;
101 
105  data_t* m_membuf;
106 
110  int64_t m_membufferpos;
111 
115  bool m_tointerleave;
116 
123  AUD_LOCAL int decode(AVPacket& packet, Buffer& buffer);
124 
128  AUD_LOCAL void init();
129 
130  // delete copy constructor and operator=
131  FFMPEGReader(const FFMPEGReader&) = delete;
132  FFMPEGReader& operator=(const FFMPEGReader&) = delete;
133 
134 public:
141  FFMPEGReader(std::string filename);
142 
149  FFMPEGReader(std::shared_ptr<Buffer> buffer);
150 
154  virtual ~FFMPEGReader();
155 
164  static int read_packet(void* opaque, uint8_t* buf, int buf_size);
165 
174  static int64_t seek_packet(void* opaque, int64_t offset, int whence);
175 
176  virtual bool isSeekable() const;
177  virtual void seek(int position);
178  virtual int getLength() const;
179  virtual int getPosition() const;
180  virtual Specs getSpecs() const;
181  virtual void read(int& length, bool& eos, sample_t* buffer);
182 };
183 
virtual int getLength() const =0
Returns an approximated length of the source in samples.
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition: Audaspace.h:116
This class represents a sound source as stream or as buffer which can be read for example by another ...
Definition: IReader.h:34
virtual void seek(int position)=0
Seeks to a specific position in the source.
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
virtual void read(int &length, bool &eos, sample_t *buffer)=0
Request to read the next length samples out of the source.
unsigned char data_t
Sample data type (format samples)
Definition: Audaspace.h:129
Specification of a sound source.
Definition: Specification.h:109
This class reads a sound file via ffmpeg.
Definition: FFMPEGReader.h:49
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality...
Definition: Buffer.h:33
Specification of a sound device.
Definition: Specification.h:119
virtual Specs getSpecs() const =0
Returns the specification of the reader.
The IReader interface.
Defines several conversion functions between different sample formats.
float sample_t
Sample type.(float samples)
Definition: Audaspace.h:126
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition: Audaspace.h:119
virtual int getPosition() const =0
Returns the position of the source as a sample count value.
#define AUD_PLUGIN_API
Used for exporting symbols in the shared library.
Definition: Audaspace.h:94
virtual bool isSeekable() const =0
Tells whether the source provides seeking functionality or not.
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition: Audaspace.h:80
The Buffer class.