/******************************************************************************** Copyright (C) 2013 Ruwen Hahn This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ********************************************************************************/ #pragma once #include #include #include #include #include "Utilities.h" template inline T align16(T t) { return (((t + 15) >> 4) << 4); } struct Parameters { private: mfxVideoParam params; std::vector ext_buffers; public: mfxExtCodingOptionSPSPPS cospspps; mfxExtVideoSignalInfo vsi; mfxExtCodingOption co; mfxExtCodingOption2 co2; operator mfxVideoParam() { return params; } operator mfxVideoParam*() { return ¶ms; } mfxVideoParam* operator&() { return ¶ms; } mfxVideoParam* operator->() { return ¶ms; } const mfxVideoParam* operator->() const { return ¶ms; } void Init(mfxU16 preset, mfxU16 profile, int fps, int keyframe_interval_frames, int bframes, int width, int height, int max_bitrate, int buffer_size, bool use_cbr, bool use_custom_params, mfxInfoMFX custom_params, decltype(mfxExtCodingOption2::LookAheadDepth) la_depth); void SetCodingOptionSPSPPS(mfxU8 *sps_buff, mfxU16 sps_size, mfxU8 *pps_buff, mfxU16 pps_size); void SetVideoSignalInfo(int full_range, int primaries, int transfer, int matrix); void AddCodingOption(); void AddCodingOption2(); Parameters(); Parameters(const Parameters&); Parameters &operator =(const Parameters&); void Dump(std::wostream&); protected: void UpdateExt(); template bool FindExt(const T& t) const { return std::find(std::begin(ext_buffers), std::end(ext_buffers), reinterpret_cast(&t)) != std::end(ext_buffers); } template void AddExt(T& t) { ext_buffers.emplace_back(reinterpret_cast(&t)); UpdateExt(); } template void InitAddExt(T& t, decltype(mfxExtBuffer::BufferId) id) { zero(t); t.Header.BufferId = id; t.Header.BufferSz = sizeof(T); AddExt(t); } }; struct EncodeCtrl { enum sei_type {SEI_USER_DATA_UNREGISTERED=0x5}; mfxEncodeCtrl ctrl; std::vector payload_list; std::vector payloads; std::vector> data_buffers; operator mfxEncodeCtrl() { return ctrl; } mfxEncodeCtrl *operator&() { return &ctrl; } void AddSEIData(sei_type type, std::vector payload); EncodeCtrl() { zero(ctrl); } };