Audaspace 1.8.0
A high level audio library.
Loading...
Searching...
No Matches
FFMPEGReader.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright 2009-2024 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
28
30#include "IReader.h"
31#include "util/Buffer.h"
32#include "file/FileInfo.h"
33
34#include <string>
35#include <memory>
36#include <vector>
37
38struct AVCodecContext;
39extern "C" {
40#include <libavformat/avformat.h>
41}
42
44
51class AUD_PLUGIN_API FFMPEGReader : public IReader
52{
53private:
57 int m_position;
58
62 DeviceSpecs m_specs;
63
67 Buffer m_pkgbuf;
68
72 int m_pkgbuf_left;
73
77 AVFormatContext* m_formatCtx;
78
82 AVCodecContext* m_codecCtx;
83
87 AVFrame* m_frame;
88
92 AVIOContext* m_aviocontext;
93
97 int m_stream;
98
102 convert_f m_convert;
103
107 std::shared_ptr<Buffer> m_membuffer;
108
112 long long m_membufferpos;
113
117 bool m_tointerleave;
118
124 AUD_LOCAL static SampleFormat convertSampleFormat(AVSampleFormat format);
125
132 AUD_LOCAL int decode(AVPacket& packet, Buffer& buffer);
133
138 AUD_LOCAL void init(int stream);
139
140 // delete copy constructor and operator=
141 FFMPEGReader(const FFMPEGReader&) = delete;
142 FFMPEGReader& operator=(const FFMPEGReader&) = delete;
143
144public:
152 FFMPEGReader(const std::string &filename, int stream = 0);
153
161 FFMPEGReader(std::shared_ptr<Buffer> buffer, int stream = 0);
162
166 virtual ~FFMPEGReader();
167
173 virtual std::vector<StreamInfo> queryStreams();
174
183 static int read_packet(void* opaque, uint8_t* buf, int buf_size);
184
193 static int64_t seek_packet(void* opaque, int64_t offset, int whence);
194
195 virtual bool isSeekable() const;
196 virtual void seek(int position);
197 virtual int getLength() const;
198 virtual int getPosition() const;
199 virtual Specs getSpecs() const;
200 virtual void read(int& length, bool& eos, sample_t* buffer);
201};
202
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition Audaspace.h:119
float sample_t
Sample type.(float samples).
Definition Audaspace.h:126
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition Audaspace.h:80
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition Audaspace.h:116
#define AUD_PLUGIN_API
Used for exporting symbols in the shared library.
Definition Audaspace.h:94
The Buffer class.
Defines several conversion functions between different sample formats.
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
The FileInfo data structures.
The IReader interface.
SampleFormat
The format of a sample.
Definition Specification.h:47
This class is a simple buffer in RAM which is 32 Byte aligned and provides resize functionality.
Definition Buffer.h:34
FFMPEGReader(const std::string &filename, int stream=0)
Creates a new reader.
static int64_t seek_packet(void *opaque, int64_t offset, int whence)
Seeks within data.
virtual void read(int &length, bool &eos, sample_t *buffer)
Request to read the next length samples out of the source.
virtual ~FFMPEGReader()
Destroys the reader and closes the file.
virtual Specs getSpecs() const
Returns the specification of the reader.
FFMPEGReader(std::shared_ptr< Buffer > buffer, int stream=0)
Creates a new reader.
virtual bool isSeekable() const
Tells whether the source provides seeking functionality or not.
virtual int getLength() const
Returns an approximated length of the source in samples.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Reads data to a memory buffer.
virtual std::vector< StreamInfo > queryStreams()
Queries the streams of a sound file.
virtual void seek(int position)
Seeks to a specific position in the source.
virtual int getPosition() const
Returns the position of the source as a sample count value.
This class represents a sound source as stream or as buffer which can be read for example by another ...
Definition IReader.h:35
Specification of a sound device.
Definition Specification.h:129
Specification of a sound source.
Definition Specification.h:119