123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #pragma once
- #include <bitset>
- #include <unordered_map>
- #include "seekable_buffer.h"
- #include "stream.h"
- #if defined(_MSC_VER)
- #include <BaseTsd.h>
- using ssize_t = SSIZE_T;
- #endif
- namespace ffmpeg {
- class Decoder : public MediaDecoder {
- public:
- Decoder();
- ~Decoder() override;
-
- bool init(
- const DecoderParameters& params,
- DecoderInCallback&& in,
- std::vector<DecoderMetadata>* metadata) override;
- int decode_all(const DecoderOutCallback& callback) override;
- void shutdown() override;
- void interrupt() override;
- protected:
-
-
-
-
- int getFrame(size_t workingTimeInMs = 100);
-
- virtual void push(DecoderOutputMessage&& buffer) = 0;
-
- virtual void onInit() {}
- public:
-
- static void logFunction(void* avcl, int level, const char* cfmt, va_list vl);
- static int shutdownFunction(void* ctx);
- static int readFunction(void* opaque, uint8_t* buf, int size);
- static int64_t seekFunction(void* opaque, int64_t offset, int whence);
-
- static void initOnce();
- int* getPrintPrefix() {
- return &printPrefix;
- }
- private:
-
- bool enableLogLevel(int level) const;
- void logCallback(int level, const std::string& message);
- int readCallback(uint8_t* buf, int size);
- int64_t seekCallback(int64_t offset, int whence);
- int shutdownCallback();
- bool openStreams(std::vector<DecoderMetadata>* metadata);
- Stream* findByIndex(int streamIndex) const;
- Stream* findByType(const MediaFormat& format) const;
- int processPacket(
- Stream* stream,
- AVPacket* packet,
- bool* gotFrame,
- bool* hasMsg,
- bool fastSeek = false);
- void flushStreams();
- void cleanUp();
- protected:
- DecoderParameters params_;
- private:
- SeekableBuffer seekableBuffer_;
- int printPrefix{1};
- std::atomic<bool> interrupted_{false};
- AVFormatContext* inputCtx_{nullptr};
- AVIOContext* avioCtx_{nullptr};
- std::unordered_map<ssize_t, std::unique_ptr<Stream>> streams_;
- std::bitset<64> inRange_;
- };
- }
|