StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
ffmpeg.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Multimedia.
5 *
6 * StormByte-Multimedia original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Multimedia source in this
20 * file. Third-party components — including FFmpeg and embedded trained data —
21 * remain under their own licenses and are not covered by the commercial grant.
22 *
23 * Neither license grants any patent rights. Any patent licenses required
24 * to use this software or third-party components must be obtained separately
25 * from the patent holders.
26 *
27 * StormByte-Multimedia is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 *
32 * You should have received a copy of the GNU Lesser General Public License
33 * version 3 along with StormByte-Multimedia. If not, see
34 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
35 *
36 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
37 */
38
39#pragma once
40
41#include <StormByte/logger/log.hxx>
50
51#include <condition_variable>
52#include <cstddef>
53#include <cstdint>
54#include <deque>
55#include <memory>
56#include <mutex>
57#include <optional>
58#include <string>
59#include <string_view>
60
62 class Host;
63 class Pipe;
64 class Pumper;
65 class Worker;
66}
67
69 class Filter;
70}
71
73 class Filters;
74 class Route;
75}
76
229 friend class StormByte::Multimedia::Backend::Pipeline::Detail::Worker::Filter;
230
231 public:
240 FFmpeg(const FFmpeg& other) = delete;
241
245 FFmpeg(FFmpeg&& other) noexcept = delete;
246
251 virtual ~FFmpeg() noexcept;
252
256 FFmpeg& operator=(const FFmpeg& other) = delete;
257
261 FFmpeg& operator=(FFmpeg&& other) noexcept = delete;
262
276 virtual enum StormByte::Multimedia::Type Media() const noexcept = 0;
277
282 std::string Name() const noexcept;
283
288 inline const std::string& Leaf() const noexcept {
289 return m_name;
290 }
291
296 inline const Pipeline::Kinds& Receives() const noexcept {
297 return m_receives;
298 }
299
304 inline const Pipeline::Kinds& Produces() const noexcept {
305 return m_produces;
306 }
307
323 virtual void Clean() noexcept = 0;
324
331 virtual void Setup() noexcept = 0;
332
343 virtual void Process(const Pipeline::Frame& frame) noexcept;
344
352 virtual void Process(const Pipeline::Packet& packet) noexcept;
353
361 virtual class Report Report() const noexcept;
362
367 Pipeline::State Status() const noexcept;
368
373 bool Failed() const noexcept;
374
379 const std::optional<std::string>& Error() const noexcept;
380
385 virtual std::size_t InputCeiling() const noexcept;
386
391 protected:
408 FFmpeg(std::shared_ptr<StormByte::Logger::Log> log,
409 std::string name, Pipeline::Kinds receives, Pipeline::Kinds produces) noexcept;
410
424 void Log(StormByte::Logger::Level level, std::string_view message) noexcept;
425
430 void Fail(std::string reason) noexcept;
431
443 void Hold(std::uint8_t n) noexcept;
444
452 void Release() noexcept;
453
458 bool Held() const noexcept;
459
464 std::uint8_t HeldFor() const noexcept;
465
473 virtual void Eof() noexcept;
474
486 virtual void LastChance(const Pipeline::Frame& frame) noexcept;
487
492 virtual void LastChance(const Pipeline::Packet& packet) noexcept;
493
505 const StormByte::Multimedia::FFmpeg::AVFrame& AVFrame() const noexcept;
506
518 const StormByte::Multimedia::FFmpeg::AVPacket& AVPacket() const noexcept;
519
530 void Save(StormByte::Multimedia::FFmpeg::AVFrame&& incoming) noexcept;
531
536 void Save(StormByte::Multimedia::FFmpeg::AVPacket&& incoming) noexcept;
537
538 private:
539 class Surface;
540
544 void Open() noexcept;
545
550 void Work(Pipeline::Item::PointerType item) noexcept;
551
556 void Finish() noexcept;
557
561 void Park() noexcept;
562
566 void CallLastChance() noexcept;
567
571 void Emit(Pipeline::Item::PointerType item) noexcept;
572
576 void Wait() noexcept;
577
581 void Launch() noexcept;
582
586 void Halt() noexcept;
587
591 void Stop() noexcept;
592
596 bool Stopping() const noexcept;
597
601 Backend::Pipeline::Host& Face() noexcept;
602
606 std::condition_variable& Wake() noexcept;
607
611 void CloseHoppers() noexcept;
612
617 void RecordWork(std::int64_t microseconds) noexcept;
618
622 void DumpWork() noexcept;
623
624 std::shared_ptr<StormByte::Logger::Log> m_log;
625 std::string m_name;
626 Pipeline::Kinds m_receives;
627 Pipeline::Kinds m_produces;
628
629 private:
630 std::condition_variable m_wake;
631 std::unique_ptr<Backend::Pipeline::Pipe> m_pipe;
632
633 protected:
638 Backend::Pipeline::Pipe& pipe() noexcept;
639
644 const Backend::Pipeline::Pipe& pipe() const noexcept;
645
646 std::unique_ptr<Surface> m_surface;
647 std::unique_ptr<Backend::Pipeline::Pumper> m_pumper;
648 std::mutex m_wait;
649 std::optional<std::string> m_error;
650 bool m_exhausted;
651 std::uint64_t m_workN;
652 std::int64_t m_workMin;
653 std::int64_t m_workMax;
654 std::int64_t m_lastWork;
655 Pipeline::Item::PointerType m_current;
656 std::deque<Pipeline::Item::PointerType> m_queue;
657 std::uint8_t m_hold;
658 std::uint8_t m_heldFor;
659 };
660
677 public:
681 Process(const Process& other) = delete;
682
686 Process(Process&& other) noexcept = delete;
687
691 ~Process() noexcept override = default;
692
696 Process& operator=(const Process& other) = delete;
697
701 Process& operator=(Process&& other) noexcept = delete;
702
703 protected:
709 Process(std::shared_ptr<StormByte::Logger::Log> log, std::string name) noexcept;
710
718 Process(std::shared_ptr<StormByte::Logger::Log> log, std::string name,
719 Pipeline::Kinds receives, Pipeline::Kinds produces) noexcept;
720 };
721
731 public:
735 Packet(const Packet& other) = delete;
736
740 Packet(Packet&& other) noexcept = delete;
741
745 ~Packet() noexcept override = default;
746
750 Packet& operator=(const Packet& other) = delete;
751
755 Packet& operator=(Packet&& other) noexcept = delete;
756
757 protected:
763 Packet(std::shared_ptr<StormByte::Logger::Log> log, std::string name) noexcept;
764
772 Packet(std::shared_ptr<StormByte::Logger::Log> log, std::string name,
773 Pipeline::Kinds receives, Pipeline::Kinds produces) noexcept;
774 };
775
804 public:
808 Analytics(const Analytics& other) = delete;
809
813 Analytics(Analytics&& other) noexcept = delete;
814
818 ~Analytics() noexcept override = default;
819
823 Analytics& operator=(const Analytics& other) = delete;
824
828 Analytics& operator=(Analytics&& other) noexcept = delete;
829
830 protected:
838 Analytics(std::shared_ptr<StormByte::Logger::Log> log, std::string name) noexcept;
839
847 Analytics(std::shared_ptr<StormByte::Logger::Log> log, std::string name,
848 Pipeline::Kinds receives, Pipeline::Kinds produces) noexcept;
849
854 void Save(StormByte::Multimedia::FFmpeg::AVFrame&& incoming) noexcept = delete;
855
860 void Save(StormByte::Multimedia::FFmpeg::AVPacket&& incoming) noexcept = delete;
861
866 void Hold(std::uint8_t n) noexcept = delete;
867
871 void Release() noexcept = delete;
872
876 bool Held() const noexcept = delete;
877
881 std::uint8_t HeldFor() const noexcept = delete;
882
887 void LastChance(const Pipeline::Frame& frame) noexcept override {
888 (void)frame;
889 }
890
895 void LastChance(const Pipeline::Packet& packet) noexcept override {
896 (void)packet;
897 }
898 };
899}
Measures units.
Definition ffmpeg.hxx:803
Analytics(const Analytics &other)=delete
Copy is not allowed.
void LastChance(const Pipeline::Packet &packet) noexcept override
Unused on Analytics.
Definition ffmpeg.hxx:895
Analytics(Analytics &&other) noexcept=delete
Move is not allowed.
~Analytics() noexcept override=default
Releases only plugin resources.
Abstract base for every StormByte Multimedia filter.
Definition ffmpeg.hxx:226
const Pipeline::Kinds & Produces() const noexcept
Kinds this filter emits.
Definition ffmpeg.hxx:304
virtual void Clean() noexcept=0
Drops per-run state.
FFmpeg(const FFmpeg &other)=delete
Copy is not allowed.
const Pipeline::Kinds & Receives() const noexcept
Kinds this filter consumes.
Definition ffmpeg.hxx:296
FFmpeg(FFmpeg &&other) noexcept=delete
Move is not allowed.
Mutates compressed packets.
Definition ffmpeg.hxx:730
Packet(const Packet &other)=delete
Copy is not allowed.
~Packet() noexcept override=default
Releases only plugin resources.
Packet(Packet &&other) noexcept=delete
Move is not allowed.
Mutates decoded frames.
Definition ffmpeg.hxx:676
Process(Process &&other) noexcept=delete
Move is not allowed.
Process(const Process &other)=delete
Copy is not allowed.
~Process() noexcept override=default
Releases only plugin resources.
Optional measurement produced by a filter.
Definition report.hxx:60
Optional facade: Between stretches, Add filters, Close.
Definition filters.hxx:76
One decoded access unit.
Definition frame.hxx:76
Facade shared by Frame and Packet.
Definition item.hxx:91
Bitmask of Kind.
Definition typedefs.hxx:148
One compressed access unit.
Definition packet.hxx:76
Owns the filter chain of one origin track and two ends.
Definition route.hxx:90
Frame and packet steps attached to a job or a raw pipeline.
Multimedia-owned pipeline stages and unit holders.
Forward so this RAII type can friend the filter base.
Definition AVFrame.hxx:63
Demux / decode / filter / encode / mux types.
State
Definition typedefs.hxx:211
Status
Definition transcoder.hxx:96
Type
Kind of media stream or codec.
Definition type.hxx:55
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47