Commit 17c738ed authored by Sébastien Gonzalve's avatar Sébastien Gonzalve Committed by Arjan Spieard

Reindent properly

parent 30da0c12
......@@ -175,11 +175,11 @@ AudioBuffer::AudioBuffer(fs::path const& file, unsigned int rate, size_t size):
m_cond.wait(l, [this]{ return m_quit || m_seek_asked; });
} catch (const std::exception& e) {
std::clog << "ffmpeg/error: " << e.what() << std::endl;
if (++errors > 2) std::clog << "ffmpeg/error: FFMPEG terminating due to multiple errors" << std::endl;
if (++errors > 2) std::clog << "ffmpeg/error: FFMPEG terminating due to multiple errors" << std::endl;
l.lock();
}
}
});
});
}
AudioBuffer::~AudioBuffer() {
......@@ -222,9 +222,9 @@ static void printFFmpegInfo() {
};
class FFmpeg::Error: public std::runtime_error {
public:
public:
Error(const FFmpeg &self, int errorValue): std::runtime_error(msgFmt(self, errorValue)) {}
private:
private:
static std::string msgFmt(const FFmpeg &self, int errorValue) {
char message[AV_ERROR_MAX_STRING_SIZE];
av_strerror(errorValue, message, AV_ERROR_MAX_STRING_SIZE);
......
......@@ -33,33 +33,33 @@ extern "C" {
/// ffmpeg class
class FFmpeg {
public:
// Exceptions thrown by class
// Exceptions thrown by class
class Eof: public std::exception {};
class Error;
friend Error;
class Error;
friend Error;
/// Decode file, depending on media type audio.
FFmpeg(fs::path const& filename, int mediaType);
void handleOneFrame();
FFmpeg(fs::path const& filename, int mediaType);
/** Seek to the chosen time. **/
void handleOneFrame();
/** Seek to the chosen time. **/
virtual void seek(double time);
/// duration
double duration() const;
virtual ~FFmpeg() = default;
virtual ~FFmpeg() = default;
protected:
static void frameDeleter(AVFrame *f) { if (f) av_frame_free(&f); }
using uFrame = std::unique_ptr<AVFrame, std::integral_constant<decltype(&frameDeleter), &frameDeleter>>;
virtual void processFrame(uFrame frame) = 0;
virtual void processFrame(uFrame frame) = 0;
struct Packet;
struct Packet;
void decodePacket(Packet &);
static void avformat_close_input(AVFormatContext *fctx);
static void avcodec_free_context(AVCodecContext *avctx);
......@@ -73,28 +73,28 @@ class FFmpeg {
};
class AudioFFmpeg : public FFmpeg {
public:
using AudioCb = std::function<void(const std::int16_t *data, size_t count, int64_t sample_position)>;
AudioFFmpeg(fs::path const& file, unsigned int rate, AudioCb audioCb);
public:
using AudioCb = std::function<void(const std::int16_t *data, size_t count, int64_t sample_position)>;
AudioFFmpeg(fs::path const& file, unsigned int rate, AudioCb audioCb);
void seek(double time) override;
protected:
void processFrame(uFrame frame) override;
private:
int64_t m_position_in_48k_frames = -1;
protected:
void processFrame(uFrame frame) override;
private:
int64_t m_position_in_48k_frames = -1;
unsigned int m_rate = 0;
AudioCb handleAudioData;
AudioCb handleAudioData;
std::unique_ptr<SwrContext, void(*)(SwrContext*)> m_resampleContext{nullptr, [] (auto p) { swr_close(p); swr_free(&p); }};
};
class VideoFFmpeg : public FFmpeg {
public:
using VideoCb = std::function<void(Bitmap)>;
VideoFFmpeg(fs::path const& file, VideoCb videoCb);
public:
using VideoCb = std::function<void(Bitmap)>;
VideoFFmpeg(fs::path const& file, VideoCb videoCb);
protected:
void processFrame(uFrame frame) override;
private:
protected:
void processFrame(uFrame frame) override;
private:
std::unique_ptr<SwsContext, void(*)(SwsContext*)> m_swsContext{nullptr, sws_freeContext};
VideoCb handleVideoData;
......@@ -102,17 +102,17 @@ private:
class AudioBuffer {
public:
using uFvec = std::unique_ptr<fvec_t, std::integral_constant<decltype(&del_fvec), &del_fvec>>;
using uFvec = std::unique_ptr<fvec_t, std::integral_constant<decltype(&del_fvec), &del_fvec>>;
AudioBuffer(fs::path const& file, unsigned int rate, size_t size = 4320256);
~AudioBuffer();
~AudioBuffer();
uFvec makePreviewBuffer();
void operator()(const std::int16_t *data, size_t count, int64_t sample_position);
bool prepare(std::int64_t pos);
bool read(float* begin, size_t count, std::int64_t pos, float volume = 1.0f);
bool terminating();
double duration();
bool terminating();
double duration();
private:
// must be called holding the mutex
......@@ -127,18 +127,15 @@ class AudioBuffer {
mutable std::mutex m_mutex;
std::condition_variable m_cond;
std::vector<std::int16_t> m_data;
std::int64_t m_write_pos = 0;
std::int64_t m_read_pos = 0;
std::int64_t m_eof_pos = -1; // -1 until we get the read end from ffmpeg
const unsigned m_sps;
const double m_duration{ 0 };
bool m_seek_asked { false };
const double m_duration{ 0 };
bool m_seek_asked { false };
bool m_quit{ false };
std::future<void> reader_thread;
};
......
......@@ -11,7 +11,7 @@ class Video {
public:
/// opens given video file
Video(fs::path const& videoFile, double videoGap = 0.0);
~Video();
~Video();
void prepare(double time); ///< Load the current video frame into a texture
void render(double time); ///< Render the prepared video frame
/// returns Dimensions of video clip
......@@ -22,26 +22,26 @@ class Video {
Bitmap m_videoFrame;
Texture m_texture;
double m_textureTime;
double m_readPosition = 0;
double m_readPosition = 0;
AnimValue m_alpha;
bool m_quit{false};
std::future<void> m_grabber;
bool m_quit{false};
std::future<void> m_grabber;
/// trys to pop a video frame from queue
bool tryPop(Bitmap& f, double timestamp);
/// Add frame to queue
void push(Bitmap&& f);
/// Clear and unlock the queue
void reset();
/// return timestamp of next frame to read
double headPosition() const { return m_queue.front().timestamp; }
/// return timestamp of next frame to read
double backPosition() const { return m_queue.back().timestamp; }
/// trys to pop a video frame from queue
bool tryPop(Bitmap& f, double timestamp);
/// Add frame to queue
void push(Bitmap&& f);
/// Clear and unlock the queue
void reset();
/// return timestamp of next frame to read
double headPosition() const { return m_queue.front().timestamp; }
/// return timestamp of next frame to read
double backPosition() const { return m_queue.back().timestamp; }
std::deque<Bitmap> m_queue;
mutable std::mutex m_mutex;
std::condition_variable m_cond;
static const unsigned m_max = 20;
bool m_seek_asked{false};
std::deque<Bitmap> m_queue;
mutable std::mutex m_mutex;
std::condition_variable m_cond;
static const unsigned m_max = 20;
bool m_seek_asked{false};
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment