#include <tbb/concurrent_unordered_map.h>\r
#include <tbb/concurrent_queue.h>\r
\r
-#include <core/producer/frame/frame_transform.h>\r
-#include <core/producer/frame/frame_factory.h>\r
+#include <core/frame/frame_transform.h>\r
+#include <core/frame/frame_factory.h>\r
#include <core/producer/frame_producer.h>\r
-#include <core/mixer/write_frame.h>\r
+#include <core/frame/write_frame.h>\r
\r
-#include <common/exception/exceptions.h>\r
-#include <common/utility/assert.h>\r
+#include <common/except.h>\r
\r
#include <tbb/parallel_for.h>\r
\r
+#include <common/assert.h>\r
#include <boost/filesystem.hpp>\r
#include <boost/lexical_cast.hpp>\r
\r
return video;\r
}\r
\r
-core::field_mode::type get_mode(const AVFrame& frame)\r
+core::field_mode get_mode(const AVFrame& frame)\r
{\r
if(!frame.interlaced_frame)\r
return core::field_mode::progressive;\r
return frame.top_field_first ? core::field_mode::upper : core::field_mode::lower;\r
}\r
\r
-core::pixel_format::type get_pixel_format(PixelFormat pix_fmt)\r
+core::pixel_format get_pixel_format(PixelFormat pix_fmt)\r
{\r
switch(pix_fmt)\r
{\r
AVPicture dummy_pict; \r
avpicture_fill(&dummy_pict, nullptr, pix_fmt == CASPAR_PIX_FMT_LUMA ? PIX_FMT_GRAY8 : pix_fmt, width, height);\r
\r
- core::pixel_format_desc desc;\r
- desc.pix_fmt = get_pixel_format(pix_fmt);\r
+ core::pixel_format_desc desc = get_pixel_format(pix_fmt);\r
\r
- switch(desc.pix_fmt)\r
+ switch(desc.format.value())\r
{\r
case core::pixel_format::gray:\r
case core::pixel_format::luma:\r
desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[1], h2, 1));\r
desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[2], h2, 1));\r
\r
- if(desc.pix_fmt == core::pixel_format::ycbcra) \r
+ if(desc.format == core::pixel_format::ycbcra) \r
desc.planes.push_back(core::pixel_format_desc::plane(dummy_pict.linesize[3], height, 1)); \r
return desc;\r
} \r
default: \r
- desc.pix_fmt = core::pixel_format::invalid;\r
+ desc.format = core::pixel_format::invalid;\r
return desc;\r
}\r
}\r
\r
int make_alpha_format(int format)\r
{\r
- switch(get_pixel_format(static_cast<PixelFormat>(format)))\r
+ switch(get_pixel_format(static_cast<PixelFormat>(format)).value())\r
{\r
case core::pixel_format::ycbcr:\r
case core::pixel_format::ycbcra:\r
}\r
}\r
\r
-safe_ptr<core::write_frame> make_write_frame(const void* tag, const safe_ptr<AVFrame>& decoded_frame, const safe_ptr<core::frame_factory>& frame_factory, int flags)\r
+spl::shared_ptr<core::write_frame> make_write_frame(const void* tag, const spl::shared_ptr<AVFrame>& decoded_frame, const spl::shared_ptr<core::frame_factory>& frame_factory, int flags)\r
{ \r
static tbb::concurrent_unordered_map<int, tbb::concurrent_queue<std::shared_ptr<SwsContext>>> sws_contexts_;\r
\r
if(decoded_frame->width < 1 || decoded_frame->height < 1)\r
- return make_safe<core::write_frame>(tag);\r
+ return frame_factory->create_frame(tag, core::pixel_format_desc(core::pixel_format::invalid));\r
\r
const auto width = decoded_frame->width;\r
const auto height = decoded_frame->height;\r
auto desc = get_pixel_format_desc(static_cast<PixelFormat>(decoded_frame->format), width, height);\r
\r
- if(flags & core::frame_producer::ALPHA_ONLY_FLAG)\r
+ if(flags & core::frame_producer::flags::alpha_only)\r
desc = get_pixel_format_desc(static_cast<PixelFormat>(make_alpha_format(decoded_frame->format)), width, height);\r
\r
std::shared_ptr<core::write_frame> write;\r
\r
- if(desc.pix_fmt == core::pixel_format::invalid)\r
+ if(desc.format == core::pixel_format::invalid)\r
{\r
auto pix_fmt = static_cast<PixelFormat>(decoded_frame->format);\r
auto target_pix_fmt = PIX_FMT_BGRA;\r
auto target_desc = get_pixel_format_desc(target_pix_fmt, width, height);\r
\r
write = frame_factory->create_frame(tag, target_desc);\r
- write->set_type(get_mode(*decoded_frame));\r
\r
std::shared_ptr<SwsContext> sws_context;\r
\r
boost::errinfo_api_function("sws_getContext"));\r
} \r
\r
- safe_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free); \r
+ spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free); \r
avcodec_get_frame_defaults(av_frame.get()); \r
if(target_pix_fmt == PIX_FMT_BGRA)\r
{\r
- auto size = avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), write->image_data().begin(), PIX_FMT_BGRA, width, height);\r
- CASPAR_VERIFY(size == write->image_data().size()); \r
+ auto size = avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), write->image_data(0).begin(), PIX_FMT_BGRA, width, height);\r
+ CASPAR_VERIFY(size == write->image_data(0).size()); \r
}\r
else\r
{\r
}\r
\r
sws_scale(sws_context.get(), decoded_frame->data, decoded_frame->linesize, 0, height, av_frame->data, av_frame->linesize); \r
- pool.push(sws_context);\r
-\r
- write->commit(); \r
+ pool.push(sws_context); \r
}\r
else\r
{\r
write = frame_factory->create_frame(tag, desc);\r
- write->set_type(get_mode(*decoded_frame));\r
\r
for(int n = 0; n < static_cast<int>(desc.planes.size()); ++n)\r
{\r
for(int y = r.begin(); y != r.end(); ++y)\r
A_memcpy(result + y*plane.linesize, decoded + y*decoded_linesize, plane.linesize);\r
}, ap);\r
-\r
- write->commit(n);\r
}\r
}\r
\r
}\r
\r
// Fix field-order if needed\r
- if(write->get_type() == core::field_mode::lower && frame_factory->get_video_format_desc().field_mode == core::field_mode::upper)\r
+ if(get_mode(*decoded_frame) == core::field_mode::lower && frame_factory->get_video_format_desc().field_mode == core::field_mode::upper)\r
write->get_frame_transform().fill_translation[1] += 1.0/static_cast<double>(frame_factory->get_video_format_desc().height);\r
- else if(write->get_type() == core::field_mode::upper && frame_factory->get_video_format_desc().field_mode == core::field_mode::lower)\r
+ else if(get_mode(*decoded_frame) == core::field_mode::upper && frame_factory->get_video_format_desc().field_mode == core::field_mode::lower)\r
write->get_frame_transform().fill_translation[1] -= 1.0/static_cast<double>(frame_factory->get_video_format_desc().height);\r
\r
- return make_safe_ptr(write);\r
+ return spl::make_shared_ptr(write);\r
+}\r
+\r
+spl::shared_ptr<AVFrame> make_av_frame(caspar::core::data_frame& frame)\r
+{\r
+ std::array<void*, 4> data = {};\r
+ for(int n = 0; n < frame.get_pixel_format_desc().planes.size(); ++n)\r
+ data[n] = frame.image_data(n).begin();\r
+\r
+ return make_av_frame(data, frame.get_pixel_format_desc());\r
+}\r
+\r
+spl::shared_ptr<AVFrame> make_av_frame(std::array<void*, 4> data, const core::pixel_format_desc& pix_desc)\r
+{\r
+ spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free); \r
+ avcodec_get_frame_defaults(av_frame.get());\r
+ \r
+ auto planes = pix_desc.planes;\r
+ auto format = pix_desc.format.value();\r
+\r
+ av_frame->width = planes[0].width;\r
+ av_frame->height = planes[0].height;\r
+ for(int n = 0; n < planes.size(); ++n) \r
+ {\r
+ av_frame->data[n] = reinterpret_cast<uint8_t*>(data[n]);\r
+ av_frame->linesize[n] = planes[n].linesize; \r
+ }\r
+ switch(format)\r
+ {\r
+ case core::pixel_format::rgba:\r
+ av_frame->format = PIX_FMT_RGBA; \r
+ break;\r
+ case core::pixel_format::argb:\r
+ av_frame->format = PIX_FMT_ARGB; \r
+ break;\r
+ case core::pixel_format::bgra:\r
+ av_frame->format = PIX_FMT_BGRA; \r
+ break;\r
+ case core::pixel_format::abgr:\r
+ av_frame->format = PIX_FMT_ABGR; \r
+ break;\r
+ case core::pixel_format::gray:\r
+ av_frame->format = PIX_FMT_GRAY8; \r
+ break;\r
+ case core::pixel_format::ycbcr:\r
+ {\r
+ int y_w = planes[0].width;\r
+ int y_h = planes[0].height;\r
+ int c_w = planes[1].width;\r
+ int c_h = planes[1].height;\r
+\r
+ if(c_h == y_h && c_w == y_w)\r
+ av_frame->format = PIX_FMT_YUV444P;\r
+ else if(c_h == y_h && c_w*2 == y_w)\r
+ av_frame->format = PIX_FMT_YUV422P;\r
+ else if(c_h == y_h && c_w*4 == y_w)\r
+ av_frame->format = PIX_FMT_YUV411P;\r
+ else if(c_h*2 == y_h && c_w*2 == y_w)\r
+ av_frame->format = PIX_FMT_YUV420P;\r
+ else if(c_h*2 == y_h && c_w*4 == y_w)\r
+ av_frame->format = PIX_FMT_YUV410P;\r
+\r
+ break;\r
+ }\r
+ case core::pixel_format::ycbcra:\r
+ av_frame->format = PIX_FMT_YUVA420P;\r
+ break;\r
+ }\r
+ return av_frame;\r
}\r
\r
bool is_sane_fps(AVRational time_base)\r
double closest_fps = 0.0;\r
for(int n = 0; n < core::video_format::count; ++n)\r
{\r
- auto format = core::video_format_desc::get(static_cast<core::video_format::type>(n));\r
+ auto format = core::video_format_desc(core::video_format(n));\r
\r
double diff1 = std::abs(format.fps - fps);\r
double diff2 = std::abs(closest_fps - fps);\r
}\r
}\r
\r
-safe_ptr<AVPacket> create_packet()\r
+spl::shared_ptr<AVPacket> create_packet()\r
{\r
- safe_ptr<AVPacket> packet(new AVPacket, [](AVPacket* p)\r
+ spl::shared_ptr<AVPacket> packet(new AVPacket, [](AVPacket* p)\r
{\r
av_free_packet(p);\r
delete p;\r
return packet;\r
}\r
\r
-safe_ptr<AVCodecContext> open_codec(AVFormatContext& context, enum AVMediaType type, int& index)\r
+spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context, enum AVMediaType type, int& index)\r
{ \r
AVCodec* decoder;\r
index = THROW_ON_ERROR2(av_find_best_stream(&context, type, -1, -1, &decoder, 0), "");\r
// decoder = decoder->next;\r
\r
THROW_ON_ERROR2(tbb_avcodec_open(context.streams[index]->codec, decoder), "");\r
- return safe_ptr<AVCodecContext>(context.streams[index]->codec, tbb_avcodec_close);\r
+ return spl::shared_ptr<AVCodecContext>(context.streams[index]->codec, tbb_avcodec_close);\r
}\r
\r
-safe_ptr<AVFormatContext> open_input(const std::wstring& filename)\r
+spl::shared_ptr<AVFormatContext> open_input(const std::wstring& filename)\r
{\r
AVFormatContext* weak_context = nullptr;\r
THROW_ON_ERROR2(avformat_open_input(&weak_context, u8(filename).c_str(), nullptr, nullptr), filename);\r
- safe_ptr<AVFormatContext> context(weak_context, av_close_input_file); \r
+ spl::shared_ptr<AVFormatContext> context(weak_context, av_close_input_file); \r
THROW_ON_ERROR2(avformat_find_stream_info(weak_context, nullptr), filename);\r
fix_meta_data(*context);\r
return context;\r
\r
bool is_valid_file(const std::wstring filename)\r
{ \r
+ if(boost::filesystem::path(filename).extension() == ".m2t")\r
+ return true;\r
+\r
std::ifstream file(filename);\r
\r
std::vector<unsigned char> buf;\r