Loading...
Searching...
No Matches
LibavEncoder.hpp
1#pragma once
2
3#include <Media/Libav.hpp>
4#if SCORE_HAS_LIBAV
5#include <Gfx/Libav/LibavOutputSettings.hpp>
6
7#include <ossia/detail/pod_vector.hpp>
8
9#include <mutex>
10#include <span>
11#include <vector>
12extern "C" {
13#include <libavcodec/avcodec.h>
14#include <libavdevice/avdevice.h>
15#include <libavformat/avformat.h>
16#include <libavutil/pixdesc.h>
17#include <libswscale/swscale.h>
18}
19namespace Gfx
20{
21
22struct OutputStream;
24{
25 explicit LibavEncoder(const LibavOutputSettings& set);
27 void enumerate();
28
29 int start();
30 int add_frame(std::span<ossia::float_vector>);
31 int add_frame(const unsigned char* data, AVPixelFormat fmt, int width, int height);
32 // Pre-converted frame: data is already in the target pixel format.
33 // planes/strides/planeCount describe the YUV plane layout.
34 int add_frame_converted(
35 const unsigned char* const planes[], const int strides[], int planeCount,
36 int width, int height);
37 int stop();
38 int stop_impl(); // Must be called with m_muxMutex held
39
40 bool available() const noexcept { return m_formatContext; }
41
43 AVFormatContext* m_formatContext{};
44
45 std::vector<OutputStream> streams;
46 std::mutex m_muxMutex; // Protects av_interleaved_write_frame (not thread-safe)
47
48 int audio_stream_index = -1;
49 int video_stream_index = -1;
50
51private:
52 // The engine hands over one block per tick; a codec with a fixed frame size
53 // wants exactly that many samples per frame, and the two numbers are rarely
54 // the same. Whole frames are cut out of here, so nothing partial is encoded.
55 std::vector<ossia::float_vector> m_audioFifo;
56 std::vector<ossia::float_vector> m_audioBlock;
57};
58
59}
60#endif
Binds the rendering pipeline to ossia processes.
Definition AssetTable.cpp:7
Definition LibavEncoder.hpp:24
Definition LibavOutputSettings.hpp:16