\r
#include <common/concurrency/executor.h>\r
#include <common/diagnostics/graph.h>\r
-#include <common/memory/memcpy.h>\r
#include <common/memory/memclr.h>\r
+#include <common/memory/memcpy.h>\r
+#include <common/memory/memshfl.h>\r
#include <common/utility/timer.h>\r
\r
#include <core/consumer/frame_consumer.h>\r
+#include <core/mixer/audio/audio_util.h>\r
\r
#include <tbb/concurrent_queue.h>\r
\r
int preroll_count_;\r
\r
const bool embedded_audio_;\r
+ const bool key_only_;\r
\r
executor executor_;\r
public:\r
- bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio) \r
+ bluefish_consumer(const core::video_format_desc& format_desc, unsigned int device_index, bool embedded_audio, bool key_only) \r
: blue_(create_blue(device_index))\r
, device_index_(device_index)\r
, format_desc_(format_desc) \r
, vid_fmt_(get_video_mode(*blue_, format_desc))\r
, preroll_count_(0)\r
, embedded_audio_(embedded_audio)\r
+ , key_only_(key_only)\r
, executor_(print())\r
{\r
executor_.set_capacity(core::consumer_buffer_depth());\r
\r
void schedule_next_video(const safe_ptr<core::read_frame>& frame)\r
{\r
- static std::vector<int16_t> silence(MAX_HANC_BUFFER_SIZE, 0);\r
+ static std::vector<int8_t> silence(MAX_HANC_BUFFER_SIZE, 0);\r
\r
executor_.begin_invoke([=]\r
{\r
// Copy to local buffers\r
\r
if(!frame->image_data().empty())\r
- fast_memcpy(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size());\r
+ {\r
+ if(key_only_) \r
+ fast_memshfl(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size(), 0x0F0F0F0F, 0x0B0B0B0B, 0x07070707, 0x03030303);\r
+ else\r
+ fast_memcpy(reserved_frames_.front()->image_data(), frame->image_data().begin(), frame->image_data().size());\r
+ }\r
else\r
fast_memclr(reserved_frames_.front()->image_data(), reserved_frames_.front()->image_size());\r
-\r
+ \r
// Sync\r
\r
sync_timer_.restart();\r
\r
if(embedded_audio_)\r
{ \r
- auto frame_audio_data = frame->audio_data().empty() ? silence.data() : const_cast<int16_t*>(frame->audio_data().begin());\r
+ auto frame_audio = core::audio_32_to_24(frame->audio_data());\r
+ auto frame_audio_data = frame_audio.size() != audio_samples ? silence.data() : frame_audio.data(); \r
\r
encode_hanc(reinterpret_cast<BLUE_UINT32*>(reserved_frames_.front()->hanc_data()), frame_audio_data, audio_samples, audio_nchannels);\r
\r
\r
void encode_hanc(BLUE_UINT32* hanc_data, void* audio_data, size_t audio_samples, size_t audio_nchannels)\r
{ \r
- const auto sample_type = AUDIO_CHANNEL_16BIT | AUDIO_CHANNEL_LITTLEENDIAN;\r
+ const auto sample_type = AUDIO_CHANNEL_24BIT | AUDIO_CHANNEL_LITTLEENDIAN;\r
const auto emb_audio_flag = blue_emb_audio_enable | blue_emb_audio_group1_enable;\r
\r
hanc_stream_info_struct hanc_stream_info;\r
const bool embedded_audio_;\r
const bool key_only_;\r
core::video_format_desc format_desc_;\r
- size_t fail_count_;\r
public:\r
\r
bluefish_consumer_proxy(size_t device_index, bool embedded_audio, bool key_only)\r
: device_index_(device_index)\r
, embedded_audio_(embedded_audio)\r
, key_only_(key_only)\r
- , fail_count_(0)\r
{\r
}\r
\r
virtual void initialize(const core::video_format_desc& format_desc)\r
{\r
format_desc_ = format_desc;\r
- consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_));\r
+ consumer_.reset(new bluefish_consumer(format_desc, device_index_, embedded_audio_, key_only_));\r
}\r
\r
virtual bool send(const safe_ptr<core::read_frame>& frame)\r
{\r
- if(!consumer_)\r
- consumer_.reset(new bluefish_consumer(format_desc_, device_index_, embedded_audio_));\r
-\r
- try\r
- {\r
- consumer_->send(frame);\r
- fail_count_ = 0;\r
- }\r
- catch(...)\r
- {\r
- consumer_.reset();\r
-\r
- if(fail_count_++ > 3)\r
- return false; // Outside didn't handle exception properly, just give up.\r
-\r
- throw;\r
- }\r
-\r
+ consumer_->send(frame);\r
return true;\r
}\r
\r
\r
return L"bluefish [" + boost::lexical_cast<std::wstring>(device_index_) + L"]";\r
}\r
-\r
- virtual bool key_only() const\r
- {\r
- return key_only_;\r
- }\r
}; \r
\r
safe_ptr<core::frame_consumer> create_bluefish_consumer(const std::vector<std::wstring>& params)\r