| 1 | #pragma once
|
|---|
| 2 | #include "FFMPEG_API.h"
|
|---|
| 3 | #include "LinkResolveHack.h"
|
|---|
| 4 | #include "IAESemaphore.h"
|
|---|
| 5 | #include "HealthData.h"
|
|---|
| 6 | #include "FrameGrabber.h"
|
|---|
| 7 |
|
|---|
| 8 | using namespace IAE::VideoProcessing;
|
|---|
| 9 |
|
|---|
| 10 | namespace IAE
|
|---|
| 11 | {
|
|---|
| 12 | namespace VideoProcessing
|
|---|
| 13 | {
|
|---|
| 14 | /// C++ Processing Modules Namespace
|
|---|
| 15 | namespace FFMPEG
|
|---|
| 16 | {
|
|---|
| 17 | class FrameProcessingThread; // Forward declaration
|
|---|
| 18 | /// <summary>
|
|---|
| 19 | /// Unmanaged interface for interacting with the FFMPEG API.
|
|---|
| 20 | /// </summary>
|
|---|
| 21 | class FFMpegEncodingAPI : public FrameGrabber
|
|---|
| 22 | {
|
|---|
| 23 | private:
|
|---|
| 24 | const AVPixelFormat INTERNAL_FORMAT = AV_PIX_FMT_YUV420P;
|
|---|
| 25 | const int DEFAULT_RTP_PAYLOAD_SIZE = 30000;
|
|---|
| 26 | const int DEFAULT_MAX_SLICE_SIZE = 20000;
|
|---|
| 27 | const int MIN_MP4_MAIN_PROFILE_BR = 2000000;
|
|---|
| 28 | const int MIN_MP4_CORE_PROFILE_BR = 384000;
|
|---|
| 29 | const int MEM_ALIGNMENT = 32;
|
|---|
| 30 |
|
|---|
| 31 | AVCodec *_codec = nullptr;
|
|---|
| 32 | AVFrame *_avFrame = nullptr;
|
|---|
| 33 | SwsContext *_swsContext = nullptr;
|
|---|
| 34 |
|
|---|
| 35 | AVCodecID _selectedCodec;
|
|---|
| 36 | AVPixelFormat _incomingFormat;
|
|---|
| 37 | AVPixelFormat _encodingFormat;
|
|---|
| 38 |
|
|---|
| 39 | int errCode = 0;
|
|---|
| 40 | int _iLastError = 0;
|
|---|
| 41 | uint64_t _ulLastPTS = 0;
|
|---|
| 42 | uint64_t _ulLastFrame = 0;
|
|---|
| 43 |
|
|---|
| 44 | bool _bIsInitialized = false;
|
|---|
| 45 | bool _bIsStopping = false;
|
|---|
| 46 | bool _bIsStopped = false;
|
|---|
| 47 | bool _bCodecOpen = false;
|
|---|
| 48 |
|
|---|
| 49 | double _dTimeScaleFactor = 1;
|
|---|
| 50 | double _dActualFPS = 30;
|
|---|
| 51 | double _dRealPTS = 0;
|
|---|
| 52 | char _codecName [80];
|
|---|
| 53 |
|
|---|
| 54 | void InitializeAPI ();
|
|---|
| 55 | void InitializeContext (AVCodecID codec, AVPixelFormat pixFmt, int64_t lBitRate, const char* accel);
|
|---|
| 56 | void SetAVOptions (int64_t lBitRate);
|
|---|
| 57 |
|
|---|
| 58 | void SetCommonOptions (void* options);
|
|---|
| 59 | void SetH26xOptions (int64_t lBitRate);
|
|---|
| 60 | void SetQSV264Options (void* options);
|
|---|
| 61 | const char* GetEncoderName (const char* accel);
|
|---|
| 62 |
|
|---|
| 63 | void PrintError (char* devNote);
|
|---|
| 64 | uint64_t GetPresentationTime (uint64_t lFrameNo);
|
|---|
| 65 |
|
|---|
| 66 | public:
|
|---|
| 67 | int m_iFramesPerSecond = 30;
|
|---|
| 68 | int m_iGroupOfPictureSize = 10;
|
|---|
| 69 | double m_dScaleFactor = 1.0;
|
|---|
| 70 |
|
|---|
| 71 | bool m_bUseInternalBuffer = false;
|
|---|
| 72 |
|
|---|
| 73 | AVCodecContext *m_encodingContext = nullptr;
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | FFMpegEncodingAPI (int iFrameHeight, int iFrameWidth, int iBytesPerPixel, int iFPS);
|
|---|
| 77 | ~FFMpegEncodingAPI ();
|
|---|
| 78 |
|
|---|
| 79 | int LastError () { return errCode; };
|
|---|
| 80 | bool Initialize (AVCodecID codec, AVPixelFormat pixFmt, int64_t lBitRate, const char* accel);
|
|---|
| 81 | void CleanUp (AVPacket *avPacket);
|
|---|
| 82 | void SetFrameRate (double dFPS);
|
|---|
| 83 | };
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|