duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

media_capture.h (2730B)


      1 // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 
      6 #include "gpu_texture.h"
      7 
      8 #include <ctime>
      9 #include <memory>
     10 #include <string>
     11 #include <string_view>
     12 #include <vector>
     13 
     14 class Error;
     15 class GPUTexture;
     16 
     17 enum class MediaCaptureBackend : u8
     18 {
     19 #ifdef _WIN32
     20   MediaFoundation,
     21 #endif
     22 #ifndef __ANDROID__
     23   FFmpeg,
     24 #endif
     25   MaxCount,
     26 };
     27 
     28 class MediaCapture
     29 {
     30 public:
     31   virtual ~MediaCapture();
     32 
     33   using ContainerName = std::pair<std::string, std::string>; // configname,longname
     34   using ContainerList = std::vector<ContainerName>;
     35   using CodecName = std::pair<std::string, std::string>; // configname,longname
     36   using CodecList = std::vector<CodecName>;
     37 
     38   static std::optional<MediaCaptureBackend> ParseBackendName(const char* str);
     39   static const char* GetBackendName(MediaCaptureBackend backend);
     40   static const char* GetBackendDisplayName(MediaCaptureBackend backend);
     41 
     42   static ContainerList GetContainerList(MediaCaptureBackend backend);
     43   static CodecList GetVideoCodecList(MediaCaptureBackend backend, const char* container);
     44   static CodecList GetAudioCodecList(MediaCaptureBackend backend, const char* container);
     45 
     46   static void AdjustVideoSize(u32* width, u32* height);
     47 
     48   static std::unique_ptr<MediaCapture> Create(MediaCaptureBackend backend, Error* error);
     49 
     50   virtual bool BeginCapture(float fps, float aspect, u32 width, u32 height, GPUTexture::Format texture_format,
     51                             u32 sample_rate, std::string path, bool capture_video, std::string_view video_codec,
     52                             u32 video_bitrate, std::string_view video_codec_args, bool capture_audio,
     53                             std::string_view audio_codec, u32 audio_bitrate, std::string_view audio_codec_args,
     54                             Error* error) = 0;
     55   virtual bool EndCapture(Error* error) = 0;
     56 
     57   // TODO: make non-virtual?
     58   virtual const std::string& GetPath() const = 0;
     59   virtual std::string GetNextCapturePath() const = 0;
     60   virtual bool IsCapturingAudio() const = 0;
     61   virtual bool IsCapturingVideo() const = 0;
     62   virtual u32 GetVideoWidth() const = 0;
     63   virtual u32 GetVideoHeight() const = 0;
     64   virtual float GetVideoFPS() const = 0;
     65 
     66   /// Returns the elapsed time in seconds.
     67   virtual time_t GetElapsedTime() const = 0;
     68 
     69   virtual float GetCaptureThreadUsage() const = 0;
     70   virtual float GetCaptureThreadTime() const = 0;
     71   virtual void UpdateCaptureThreadUsage(double pct_divider, double time_divider) = 0;
     72 
     73   virtual GPUTexture* GetRenderTexture() = 0;
     74   virtual bool DeliverVideoFrame(GPUTexture* stex) = 0;
     75   virtual bool DeliverAudioFrames(const s16* frames, u32 num_frames) = 0;
     76   virtual void Flush() = 0;
     77 };