OpenShot Library | libopenshot 1.1.1
AudioReaderSource.h
Go to the documentation of this file.
1
9// Copyright (c) 2008-2019 OpenShot Studios, LLC
10//
11// SPDX-License-Identifier: LGPL-3.0-or-later
12
13#ifndef OPENSHOT_AUDIOREADERSOURCE_H
14#define OPENSHOT_AUDIOREADERSOURCE_H
15
16#include <atomic>
17#include <mutex>
18
19#include "ReaderBase.h"
20#include "Qt/VideoCacheThread.h"
21
22#include <AppConfig.h>
23#include <juce_audio_basics/juce_audio_basics.h>
24
26namespace openshot
27{
28 class Frame;
34 class AudioReaderSource : public juce::PositionableAudioSource
35 {
36 private:
37 std::atomic<int64_t> stream_position;
38 int64_t frame_position;
39 std::atomic<int> speed;
40
41 ReaderBase *reader;
42 std::shared_ptr<Frame> frame;
43 std::mutex seek_mutex;
44 std::atomic<uint64_t> seek_generation{0};
45 std::atomic<int64_t> requested_frame;
46 uint64_t applied_generation = 0;
47 std::atomic<uint64_t> published_generation{0};
48 std::atomic<uint64_t> speed_generation{0};
49 int64_t sample_position;
50 openshot::VideoCacheThread *videoCache;
51
52 public:
53
57 AudioReaderSource(ReaderBase *audio_reader, int64_t starting_frame_number);
58
61
64 void getNextAudioBlock (const juce::AudioSourceChannelInfo& info);
65
67 void prepareToPlay(int, double);
68
70 void releaseResources();
71
74 void setNextReadPosition (juce::int64 newPosition) { stream_position = newPosition; };
75
77 juce::int64 getNextReadPosition() const { return stream_position; };
78
81
83 bool isLooping() const { return false; };
84
87 void setLooping (bool shouldLoop) { };
88
90 std::shared_ptr<Frame> getFrame() const;
91
93 void setSpeed(int new_speed) { if (speed.exchange(new_speed) != new_speed) ++speed_generation; }
95 int getSpeed() const { return speed; }
96
98 void setVideoCache(openshot::VideoCacheThread *newCache) { videoCache = newCache; }
99
101 void Reader(ReaderBase *audio_reader) { reader = audio_reader; }
103 ReaderBase* Reader() const { return reader; }
104
106 void Seek(int64_t new_position);
107
108 };
109
110}
111
112#endif
#define int64
Definition: Clip.h:17
Header file for ReaderBase class.
Header file for VideoCacheThread class.
This class is used to expose any ReaderBase derived class as an AudioSource in JUCE.
std::shared_ptr< Frame > getFrame() const
Return the current frame object.
AudioReaderSource(ReaderBase *audio_reader, int64_t starting_frame_number)
The cache thread (for pre-roll checking)
int getSpeed() const
Get Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster,...
void releaseResources()
Release all resources.
void Reader(ReaderBase *audio_reader)
Set Reader.
juce::int64 getNextReadPosition() const
Get the next read position of this source.
void setLooping(bool shouldLoop)
This method is ignored (we do not support looping audio playback)
juce::int64 getTotalLength() const
Get the total length (in samples) of this audio source.
void setSpeed(int new_speed)
Set Speed (The speed and direction to playback a reader (1=normal, 2=fast, 3=faster,...
void prepareToPlay(int, double)
Prepare to play this audio source.
ReaderBase * Reader() const
Get Reader.
void Seek(int64_t new_position)
Seek to a specific frame.
void getNextAudioBlock(const juce::AudioSourceChannelInfo &info)
Get the next block of audio samples.
void setVideoCache(openshot::VideoCacheThread *newCache)
Set playback video cache thread (for pre-roll reference)
void setNextReadPosition(juce::int64 newPosition)
Set the next read position of this source.
bool isLooping() const
Looping is not support in OpenShot audio playback (this is always false)
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:76
Handles prefetching and caching of video/audio frames for smooth playback.
This namespace is the default namespace for all code in the openshot library.
Definition: AnimatedCurve.h:24