]> git.sesse.net Git - casparcg/commitdiff
2.0.0.2: Merged mixer into core/mixer.
authorronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 28 Apr 2011 13:43:58 +0000 (13:43 +0000)
committerronag <ronag@362d55ac-95cf-4e76-9f9a-cbaa9c17b72d>
Thu, 28 Apr 2011 13:43:58 +0000 (13:43 +0000)
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches/2.0.0.2@663 362d55ac-95cf-4e76-9f9a-cbaa9c17b72d

25 files changed:
casparcg.sln
core/core.vcxproj
core/core.vcxproj.filters
core/mixer/audio/audio_mixer.cpp [new file with mode: 0644]
core/mixer/audio/audio_mixer.h [new file with mode: 0644]
core/mixer/frame_mixer_device.cpp [new file with mode: 0644]
core/mixer/frame_mixer_device.h [new file with mode: 0644]
core/mixer/gpu/device_buffer.cpp [new file with mode: 0644]
core/mixer/gpu/device_buffer.h [new file with mode: 0644]
core/mixer/gpu/gpu_read_frame.cpp [new file with mode: 0644]
core/mixer/gpu/gpu_read_frame.h [new file with mode: 0644]
core/mixer/gpu/gpu_write_frame.cpp [new file with mode: 0644]
core/mixer/gpu/gpu_write_frame.h [new file with mode: 0644]
core/mixer/gpu/host_buffer.cpp [new file with mode: 0644]
core/mixer/gpu/host_buffer.h [new file with mode: 0644]
core/mixer/gpu/ogl_device.cpp [new file with mode: 0644]
core/mixer/gpu/ogl_device.h [new file with mode: 0644]
core/mixer/image/image_kernel.cpp [new file with mode: 0644]
core/mixer/image/image_kernel.h [new file with mode: 0644]
core/mixer/image/image_mixer.cpp [new file with mode: 0644]
core/mixer/image/image_mixer.h [new file with mode: 0644]
modules/ffmpeg/producer/video/video_decoder.h
protocol/protocol.vcxproj
shell/main.cpp
shell/shell.vcxproj

index 781e618cb55f3c7b516039e9a92c320821a60005..22f813e65bb2a1af3e1eb91c9a5099cf5dfe4a9b 100644 (file)
@@ -9,8 +9,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "shell", "shell\shell.vcxpro
 EndProject\r
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "protocol", "protocol\protocol.vcxproj", "{2040B361-1FB6-488E-84A5-38A580DA90DE}"\r
 EndProject\r
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mixer", "mixer\mixer.vcxproj", "{477E12A4-1B28-4FF7-B46D-76606BDD1891}"\r
-EndProject\r
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "documentation", "documentation", "{32079541-68ED-4319-91FB-0FF041642679}"\r
        ProjectSection(SolutionItems) = preProject\r
                ..\CasparCG 2.0 Preliminary Change Log.txt = ..\CasparCG 2.0 Preliminary Change Log.txt\r
@@ -80,14 +78,6 @@ Global
                {2040B361-1FB6-488E-84A5-38A580DA90DE}.Profile|Win32.Build.0 = Profile|Win32\r
                {2040B361-1FB6-488E-84A5-38A580DA90DE}.Release|Win32.ActiveCfg = Release|Win32\r
                {2040B361-1FB6-488E-84A5-38A580DA90DE}.Release|Win32.Build.0 = Release|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Debug|Win32.ActiveCfg = Debug|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Debug|Win32.Build.0 = Debug|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Develop|Win32.ActiveCfg = Develop|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Develop|Win32.Build.0 = Develop|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Profile|Win32.ActiveCfg = Profile|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Profile|Win32.Build.0 = Profile|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Release|Win32.ActiveCfg = Release|Win32\r
-               {477E12A4-1B28-4FF7-B46D-76606BDD1891}.Release|Win32.Build.0 = Release|Win32\r
                {69313D25-9F54-4FC9-9872-628A4DD79464}.Debug|Win32.ActiveCfg = Debug|Win32\r
                {69313D25-9F54-4FC9-9872-628A4DD79464}.Debug|Win32.Build.0 = Debug|Win32\r
                {69313D25-9F54-4FC9-9872-628A4DD79464}.Develop|Win32.ActiveCfg = Develop|Win32\r
index 6ea3fb986263168442296789ee1aed2d18a9446c..c2aae767d7a7ded708932adc73f18c0c1e90ae45 100644 (file)
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)tmp\$(Configuration)\</IntDir>\r
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">$(ProjectDir)tmp\$(Configuration)\</IntDir>\r
     <IntDir Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">$(ProjectDir)tmp\$(Configuration)\</IntDir>\r
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;$(IncludePath)</IncludePath>\r
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;$(IncludePath)</IncludePath>\r
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;$(IncludePath)</IncludePath>\r
-    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;$(IncludePath)</IncludePath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;..\dependencies\SFML-1.6\include;..\dependencies\GLee5_4;$(IncludePath)</IncludePath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;..\dependencies\SFML-1.6\include;..\dependencies\GLee5_4;$(IncludePath)</IncludePath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;..\dependencies\SFML-1.6\include;..\dependencies\GLee5_4;$(IncludePath)</IncludePath>\r
+    <IncludePath Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">..\;..\dependencies\boost_1_44_0\;..\dependencies\tbb30_20100406oss\include\;..\dependencies\SFML-1.6\include;..\dependencies\GLee5_4;$(IncludePath)</IncludePath>\r
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\dependencies\BluefishSDK_V5_8_0_31\Lib\;..\dependencies\boost_1_44_0\stage\lib\;..\dependencies\ffmpeg 0.6\lib\;..\dependencies\FreeImage\Dist\;..\dependencies\GLee5_4\;..\dependencies\SFML-1.6\lib\;..\dependencies\tbb30_20100406oss\lib\ia32\vc10\;$(LibraryPath)</LibraryPath>\r
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\dependencies\BluefishSDK_V5_8_0_31\Lib\;..\dependencies\boost_1_44_0\stage\lib\;..\dependencies\ffmpeg 0.6\lib\;..\dependencies\FreeImage\Dist\;..\dependencies\GLee5_4\;..\dependencies\SFML-1.6\lib\;..\dependencies\tbb30_20100406oss\lib\ia32\vc10\;$(LibraryPath)</LibraryPath>\r
     <LibraryPath Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">..\dependencies\BluefishSDK_V5_8_0_31\Lib\;..\dependencies\boost_1_44_0\stage\lib\;..\dependencies\ffmpeg 0.6\lib\;..\dependencies\FreeImage\Dist\;..\dependencies\GLee5_4\;..\dependencies\SFML-1.6\lib\;..\dependencies\tbb30_20100406oss\lib\ia32\vc10\;$(LibraryPath)</LibraryPath>\r
     <ClInclude Include="consumer\frame\read_frame.h" />\r
     <ClInclude Include="consumer\frame_consumer_device.h" />\r
     <ClInclude Include="consumer\frame_consumer.h" />\r
+    <ClInclude Include="mixer\audio\audio_mixer.h" />\r
+    <ClInclude Include="mixer\frame_mixer_device.h" />\r
+    <ClInclude Include="mixer\gpu\device_buffer.h" />\r
+    <ClInclude Include="mixer\gpu\gpu_read_frame.h" />\r
+    <ClInclude Include="mixer\gpu\gpu_write_frame.h" />\r
+    <ClInclude Include="mixer\gpu\host_buffer.h" />\r
+    <ClInclude Include="mixer\gpu\ogl_device.h" />\r
+    <ClInclude Include="mixer\image\image_kernel.h" />\r
+    <ClInclude Include="mixer\image\image_mixer.h" />\r
     <ClInclude Include="producer\color\color_producer.h" />\r
     <ClInclude Include="producer\frame\audio_transform.h" />\r
     <ClInclude Include="producer\frame\basic_frame.h" />\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
     </ClCompile>\r
+    <ClCompile Include="mixer\audio\audio_mixer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\frame_mixer_device.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\device_buffer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\gpu_read_frame.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\gpu_write_frame.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\host_buffer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\ogl_device.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\image\image_kernel.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\image\image_mixer.cpp">\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Profile|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Develop|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
+    </ClCompile>\r
     <ClCompile Include="producer\color\color_producer.cpp">\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
       <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">../../StdAfx.h</PrecompiledHeaderFile>\r
     <ProjectReference Include="..\common\common.vcxproj">\r
       <Project>{02308602-7fe0-4253-b96e-22134919f56a}</Project>\r
     </ProjectReference>\r
-    <ProjectReference Include="..\mixer\mixer.vcxproj">\r
-      <Project>{477e12a4-1b28-4ff7-b46d-76606bdd1891}</Project>\r
-    </ProjectReference>\r
   </ItemGroup>\r
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />\r
   <ImportGroup Label="ExtensionTargets">\r
index 95696ccc74267ed04f5a1ef1bc3718795a59e4ed..8475007067709a96093985ef8438fda4272b9de6 100644 (file)
     <Filter Include="consumer\frame">\r
       <UniqueIdentifier>{fc8d2ce0-e849-4f8e-83bf-494ab4455b80}</UniqueIdentifier>\r
     </Filter>\r
+    <Filter Include="mixer">\r
+      <UniqueIdentifier>{e480e128-a351-4dc6-a7ab-f58b480f6afd}</UniqueIdentifier>\r
+    </Filter>\r
+    <Filter Include="mixer\audio">\r
+      <UniqueIdentifier>{0951ac32-6cd0-4a9f-865d-6f86600f12f8}</UniqueIdentifier>\r
+    </Filter>\r
+    <Filter Include="mixer\image">\r
+      <UniqueIdentifier>{1cca1d41-f9b1-4b7b-b34f-8a88dcb5b904}</UniqueIdentifier>\r
+    </Filter>\r
+    <Filter Include="mixer\gpu">\r
+      <UniqueIdentifier>{2d2ae7ff-03d7-4e8c-a298-fb41ee42a885}</UniqueIdentifier>\r
+    </Filter>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClInclude Include="producer\transition\transition_producer.h">\r
     <ClInclude Include="producer\frame\frame_factory.h">\r
       <Filter>producer\frame</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="mixer\frame_mixer_device.h">\r
+      <Filter>mixer</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\image\image_kernel.h">\r
+      <Filter>mixer\image</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\image\image_mixer.h">\r
+      <Filter>mixer\image</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\gpu\gpu_read_frame.h">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\gpu\gpu_write_frame.h">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\gpu\host_buffer.h">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\gpu\ogl_device.h">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\gpu\device_buffer.h">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClInclude>\r
+    <ClInclude Include="mixer\audio\audio_mixer.h">\r
+      <Filter>mixer\audio</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="producer\transition\transition_producer.cpp">\r
       <Filter>producer\frame</Filter>\r
     </ClCompile>\r
     <ClCompile Include="video_format.cpp" />\r
+    <ClCompile Include="mixer\frame_mixer_device.cpp">\r
+      <Filter>mixer</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\image\image_mixer.cpp">\r
+      <Filter>mixer\image</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\image\image_kernel.cpp">\r
+      <Filter>mixer\image</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\gpu_read_frame.cpp">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\gpu_write_frame.cpp">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\host_buffer.cpp">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\ogl_device.cpp">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\gpu\device_buffer.cpp">\r
+      <Filter>mixer\gpu</Filter>\r
+    </ClCompile>\r
+    <ClCompile Include="mixer\audio\audio_mixer.cpp">\r
+      <Filter>mixer\audio</Filter>\r
+    </ClCompile>\r
   </ItemGroup>\r
 </Project>
\ No newline at end of file
diff --git a/core/mixer/audio/audio_mixer.cpp b/core/mixer/audio/audio_mixer.cpp
new file mode 100644 (file)
index 0000000..7ab35d1
--- /dev/null
@@ -0,0 +1,121 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "audio_mixer.h"\r
+\r
+#include "../gpu/gpu_write_frame.h"\r
+\r
+#include <core/producer/frame/audio_transform.h>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+struct audio_mixer::implementation\r
+{\r
+       std::vector<short> audio_data_;\r
+       std::stack<core::audio_transform> transform_stack_;\r
+\r
+       std::map<int, core::audio_transform> prev_audio_transforms_;\r
+       std::map<int, core::audio_transform> next_audio_transforms_;\r
+\r
+public:\r
+       implementation()\r
+       {\r
+               transform_stack_.push(core::audio_transform());\r
+       }\r
+       \r
+       void begin(const core::basic_frame& frame)\r
+       {\r
+               transform_stack_.push(transform_stack_.top()*frame.get_audio_transform());\r
+       }\r
+\r
+       void visit(const core::write_frame& frame)\r
+       {\r
+               if(!transform_stack_.top().get_has_audio())\r
+                       return;\r
+\r
+               auto& audio_data = frame.audio_data();\r
+               auto tag = frame.tag(); // Get the identifier for the audio-stream.\r
+\r
+               if(audio_data_.empty())\r
+                       audio_data_.resize(audio_data.size(), 0);\r
+               \r
+               auto next = transform_stack_.top();\r
+               auto prev = next;\r
+\r
+               auto it = prev_audio_transforms_.find(tag);\r
+               if(it != prev_audio_transforms_.end())\r
+                       prev = it->second;\r
+                               \r
+               next_audio_transforms_[tag] = next; // Store all active tags, inactive tags will be removed in end_pass.\r
+               \r
+               auto next_gain = next.get_gain();\r
+               auto prev_gain = prev.get_gain();\r
+               \r
+               if(next_gain < 0.001 && prev_gain < 0.001)\r
+                       return;\r
+\r
+               tbb::parallel_for\r
+               (\r
+                       tbb::blocked_range<size_t>(0, audio_data.size()),\r
+                       [&](const tbb::blocked_range<size_t>& r)\r
+                       {\r
+                               for(size_t n = r.begin(); n < r.end(); ++n)\r
+                               {\r
+                                       double alpha = static_cast<double>(n)/static_cast<double>(audio_data_.size());\r
+                                       double sample_gain = prev_gain * (1.0 - alpha) + next_gain * alpha;\r
+                                       int sample = static_cast<int>(audio_data[n]);\r
+                                       sample = (static_cast<int>(sample_gain*static_cast<double>(1<<15))*sample)>>15;\r
+                                       audio_data_[n] = static_cast<short>((static_cast<int>(audio_data_[n]) + sample) & 0xFFFF);\r
+                               }\r
+                       }\r
+               );\r
+       }\r
+\r
+\r
+       void begin(const core::audio_transform& transform)\r
+       {\r
+               transform_stack_.push(transform_stack_.top()*transform);\r
+       }\r
+               \r
+       void end()\r
+       {\r
+               transform_stack_.pop();\r
+       }\r
+\r
+       std::vector<short> begin_pass()\r
+       {\r
+               return std::move(audio_data_);\r
+       }\r
+\r
+       void end_pass()\r
+       {\r
+               prev_audio_transforms_ = std::move(next_audio_transforms_);\r
+       }\r
+};\r
+\r
+audio_mixer::audio_mixer() : impl_(new implementation()){}\r
+void audio_mixer::begin(const core::basic_frame& frame){impl_->begin(frame);}\r
+void audio_mixer::visit(core::write_frame& frame){impl_->visit(frame);}\r
+void audio_mixer::end(){impl_->end();}\r
+std::vector<short> audio_mixer::begin_pass(){return impl_->begin_pass();}      \r
+void audio_mixer::end_pass(){impl_->end_pass();}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/audio/audio_mixer.h b/core/mixer/audio/audio_mixer.h
new file mode 100644 (file)
index 0000000..92f20ac
--- /dev/null
@@ -0,0 +1,46 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <core/producer/frame/frame_visitor.h>\r
+#include <core/producer/frame/audio_transform.h>\r
+\r
+#include <boost/noncopyable.hpp>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class audio_mixer : public core::frame_visitor, boost::noncopyable\r
+{\r
+public:\r
+       audio_mixer();\r
+\r
+       virtual void begin(const core::basic_frame& frame);\r
+       virtual void visit(core::write_frame& frame);\r
+       virtual void end();\r
+\r
+       std::vector<short> begin_pass();\r
+       void end_pass();\r
+\r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/frame_mixer_device.cpp b/core/mixer/frame_mixer_device.cpp
new file mode 100644 (file)
index 0000000..1d2dda8
--- /dev/null
@@ -0,0 +1,318 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../StdAfx.h"\r
+\r
+#include "frame_mixer_device.h"\r
+\r
+#include "gpu/gpu_read_frame.h"\r
+#include "gpu/gpu_write_frame.h"\r
+\r
+#include "audio/audio_mixer.h"\r
+#include "image/image_mixer.h"\r
+\r
+#include <common/exception/exceptions.h>\r
+#include <common/concurrency/executor.h>\r
+#include <common/diagnostics/graph.h>\r
+#include <common/utility/assert.h>\r
+#include <common/utility/timer.h>\r
+#include <common/utility/tweener.h>\r
+\r
+#include <core/producer/frame/audio_transform.h>\r
+#include <core/producer/frame/image_transform.h>\r
+\r
+#include <core/video_format.h>\r
+\r
+#include <boost/fusion/container/map.hpp>\r
+#include <boost/fusion/include/at_key.hpp>\r
+\r
+#include <unordered_map>\r
+\r
+namespace caspar { namespace mixer {\r
+               \r
+template<typename T>\r
+class tweened_transform\r
+{\r
+       T source_;\r
+       T dest_;\r
+       int duration_;\r
+       int time_;\r
+       tweener_t tweener_;\r
+public:        \r
+       tweened_transform()\r
+               : duration_(0)\r
+               , time_(0)\r
+               , tweener_(get_tweener(L"linear")){}\r
+       tweened_transform(const T& source, const T& dest, int duration, const std::wstring& tween = L"linear")\r
+               : source_(source)\r
+               , dest_(dest)\r
+               , duration_(duration)\r
+               , time_(0)\r
+               , tweener_(get_tweener(tween)){}\r
+       \r
+       T fetch()\r
+       {\r
+               return time_ == duration_ ? dest_ : tween(static_cast<double>(time_), source_, dest_, static_cast<double>(duration_), tweener_);\r
+       }\r
+\r
+       T fetch_and_tick(int num)\r
+       {                                               \r
+               time_ = std::min(time_+num, duration_);\r
+               return fetch();\r
+       }\r
+};\r
+\r
+struct frame_mixer_device::implementation : boost::noncopyable\r
+{              \r
+       const core::video_format_desc format_desc_;\r
+\r
+       safe_ptr<diagnostics::graph> diag_;\r
+       timer perf_timer_;\r
+       timer wait_perf_timer_;\r
+\r
+       audio_mixer     audio_mixer_;\r
+       image_mixer image_mixer_;\r
+\r
+       output_t output_;\r
+       \r
+       typedef std::unordered_map<int, tweened_transform<core::image_transform>> image_transforms;\r
+       typedef std::unordered_map<int, tweened_transform<core::audio_transform>> audio_transforms;\r
+\r
+       boost::fusion::map<boost::fusion::pair<core::image_transform, image_transforms>,\r
+                                       boost::fusion::pair<core::audio_transform, audio_transforms>> transforms_;\r
+       \r
+       boost::fusion::map<boost::fusion::pair<core::image_transform, tweened_transform<core::image_transform>>,\r
+                                       boost::fusion::pair<core::audio_transform, tweened_transform<core::audio_transform>>> root_transforms_;\r
+\r
+       executor executor_;\r
+public:\r
+       implementation(const core::video_format_desc& format_desc) \r
+               : format_desc_(format_desc)\r
+               , diag_(diagnostics::create_graph(narrow(print())))\r
+               , image_mixer_(format_desc)\r
+               , executor_(L"frame_mixer_device")\r
+       {\r
+               diag_->add_guide("frame-time", 0.5f);   \r
+               diag_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f));\r
+               diag_->set_color("tick-time", diagnostics::color(0.1f, 0.7f, 0.8f));\r
+               diag_->set_color("input-buffer", diagnostics::color(1.0f, 1.0f, 0.0f));         \r
+               executor_.start();\r
+               executor_.set_capacity(2);\r
+               CASPAR_LOG(info) << print() << L" Successfully initialized.";   \r
+       }\r
+\r
+       boost::signals2::connection connect(const output_t::slot_type& subscriber)\r
+       {\r
+               return output_.connect(subscriber);\r
+       }\r
+\r
+       boost::unique_future<safe_ptr<const host_buffer>> mix_image(std::map<int, safe_ptr<core::basic_frame>> frames)\r
+       {               \r
+               auto& root_image_transform = boost::fusion::at_key<core::image_transform>(root_transforms_);\r
+               auto& image_transforms = boost::fusion::at_key<core::image_transform>(transforms_);\r
+\r
+               auto image = image_mixer_.begin_pass();\r
+               BOOST_FOREACH(auto& frame, frames)\r
+               {\r
+                       if(format_desc_.mode != core::video_mode::progressive)\r
+                       {\r
+                               auto frame1 = make_safe<core::basic_frame>(frame.second);\r
+                               auto frame2 = make_safe<core::basic_frame>(frame.second);\r
+                               \r
+                               frame1->get_image_transform() = root_image_transform.fetch_and_tick(1)*image_transforms[frame.first].fetch_and_tick(1);\r
+                               frame2->get_image_transform() = root_image_transform.fetch_and_tick(1)*image_transforms[frame.first].fetch_and_tick(1);\r
+\r
+                               if(frame1->get_image_transform() != frame2->get_image_transform())\r
+                                       core::basic_frame::interlace(frame1, frame2, format_desc_.mode)->accept(image_mixer_);\r
+                               else\r
+                                       frame2->accept(image_mixer_);\r
+                       }\r
+                       else\r
+                       {\r
+                               auto frame1 = make_safe<core::basic_frame>(frame.second);\r
+                               frame1->get_image_transform() = root_image_transform.fetch_and_tick(1)*image_transforms[frame.first].fetch_and_tick(1);\r
+                               frame1->accept(image_mixer_);\r
+                       }\r
+               }\r
+               image_mixer_.end_pass();\r
+               return std::move(image);\r
+       }\r
+\r
+       std::vector<short> mix_audio(const std::map<int, safe_ptr<core::basic_frame>>& frames)\r
+       {\r
+               auto& root_audio_transform = boost::fusion::at_key<core::audio_transform>(root_transforms_);\r
+               auto& audio_transforms = boost::fusion::at_key<core::audio_transform>(transforms_);\r
+\r
+               auto audio = audio_mixer_.begin_pass();\r
+               BOOST_FOREACH(auto& frame, frames)\r
+               {\r
+                       int num = format_desc_.mode == core::video_mode::progressive ? 1 : 2;\r
+\r
+                       auto frame1 = make_safe<core::basic_frame>(frame.second);\r
+                       frame1->get_audio_transform() = root_audio_transform.fetch_and_tick(num)*audio_transforms[frame.first].fetch_and_tick(num);\r
+                       frame1->accept(audio_mixer_);\r
+               }\r
+               audio_mixer_.end_pass();\r
+               return audio;\r
+       }\r
+               \r
+       void send(const std::map<int, safe_ptr<core::basic_frame>>& frames)\r
+       {                       \r
+               executor_.begin_invoke([=]\r
+               {                       \r
+                       perf_timer_.reset();\r
+\r
+                       auto image_future = mix_image(frames);\r
+                       auto audio = mix_audio(frames);\r
+                       auto image = image_future.get();\r
+\r
+                       diag_->update_value("frame-time", static_cast<float>(perf_timer_.elapsed()/format_desc_.interval*0.5));\r
+\r
+                       output_(make_safe<const gpu_read_frame>(std::move(image), std::move(audio)));\r
+\r
+                       diag_->update_value("tick-time", static_cast<float>(wait_perf_timer_.elapsed()/format_desc_.interval*0.5));\r
+                       wait_perf_timer_.reset();\r
+\r
+                       diag_->set_value("input-buffer", static_cast<float>(executor_.size())/static_cast<float>(executor_.capacity()));\r
+               });\r
+               diag_->set_value("input-buffer", static_cast<float>(executor_.size())/static_cast<float>(executor_.capacity()));\r
+       }\r
+               \r
+       safe_ptr<core::write_frame> create_frame(void* tag, const core::pixel_format_desc& desc)\r
+       {\r
+               return make_safe<gpu_write_frame>(reinterpret_cast<int>(tag), desc, image_mixer_.create_buffers(desc));\r
+       }\r
+                       \r
+       template<typename T>    \r
+       void set_transform(const T& transform, int mix_duration, const std::wstring& tween)\r
+       {\r
+               executor_.invoke([&]\r
+               {\r
+                       auto& root = boost::fusion::at_key<T>(root_transforms_);\r
+\r
+                       auto src = root.fetch();\r
+                       auto dst = transform;\r
+                       root = tweened_transform<T>(src, dst, mix_duration, tween);\r
+               });\r
+       }\r
+               \r
+       template<typename T>\r
+       void set_transform(int index, const T& transform, int mix_duration, const std::wstring& tween)\r
+       {\r
+               executor_.invoke([&]\r
+               {\r
+                       auto& transforms = boost::fusion::at_key<T>(transforms_);\r
+\r
+                       auto src = transforms[index].fetch();\r
+                       auto dst = transform;\r
+                       transforms[index] = tweened_transform<T>(src, dst, mix_duration, tween);\r
+               });\r
+       }\r
+               \r
+       template<typename T>\r
+       void apply_transform(const std::function<T(const T&)>& transform, int mix_duration, const std::wstring& tween)\r
+       {\r
+               return executor_.invoke([&]\r
+               {\r
+                       auto& root = boost::fusion::at_key<T>(root_transforms_);\r
+\r
+                       auto src = root.fetch();\r
+                       auto dst = transform(src);\r
+                       root = tweened_transform<T>(src, dst, mix_duration, tween);\r
+               });\r
+       }\r
+               \r
+       template<typename T>\r
+       void apply_transform(int index, const std::function<T(T)>& transform, int mix_duration, const std::wstring& tween)\r
+       {\r
+               executor_.invoke([&]\r
+               {\r
+                       auto& transforms = boost::fusion::at_key<T>(transforms_);\r
+\r
+                       auto src = transforms[index].fetch();\r
+                       auto dst = transform(src);\r
+                       transforms[index] = tweened_transform<T>(src, dst, mix_duration, tween);\r
+               });\r
+       }\r
+\r
+       template<typename T>\r
+       void reset_transform(int mix_duration, const std::wstring& tween)\r
+       {\r
+               executor_.invoke([&]\r
+               {\r
+                       auto& transforms = boost::fusion::at_key<T>(transforms_);\r
+\r
+                       BOOST_FOREACH(auto& t, transforms)                      \r
+                                t.second = tweened_transform<T>(t.second.fetch(), T(), mix_duration, tween);                   \r
+                       set_transform(T(), mix_duration, tween);\r
+               });\r
+       }\r
+\r
+       template<typename T>\r
+       void reset_transform(int index, int mix_duration, const std::wstring& tween)\r
+       {\r
+               executor_.invoke([&]\r
+               {               \r
+                       set_transform(T(), mix_duration, tween);\r
+               });\r
+       }\r
+       \r
+       std::wstring print() const\r
+       {\r
+               return L"frame_mixer_device";\r
+       }\r
+};\r
+       \r
+frame_mixer_device::frame_mixer_device(const core::video_format_desc& format_desc) : impl_(new implementation(format_desc)){}\r
+frame_mixer_device::frame_mixer_device(frame_mixer_device&& other) : impl_(std::move(other.impl_)){}\r
+boost::signals2::connection frame_mixer_device::connect(const output_t::slot_type& subscriber){return impl_->connect(subscriber);}\r
+void frame_mixer_device::send(const std::map<int, safe_ptr<core::basic_frame>>& frames){impl_->send(frames);}\r
+const core::video_format_desc& frame_mixer_device::get_video_format_desc() const { return impl_->format_desc_; }\r
+safe_ptr<core::write_frame> frame_mixer_device::create_frame(void* tag, const core::pixel_format_desc& desc){ return impl_->create_frame(tag, desc); }         \r
+safe_ptr<core::write_frame> frame_mixer_device::create_frame(void* tag, size_t width, size_t height, core::pixel_format::type pix_fmt)\r
+{\r
+       // Create bgra frame\r
+       core::pixel_format_desc desc;\r
+       desc.pix_fmt = pix_fmt;\r
+       desc.planes.push_back( core::pixel_format_desc::plane(width, height, 4));\r
+       return create_frame(tag, desc);\r
+}\r
+                       \r
+safe_ptr<core::write_frame> frame_mixer_device::create_frame(void* tag, core::pixel_format::type pix_fmt)\r
+{\r
+       // Create bgra frame with output resolution\r
+       core::pixel_format_desc desc;\r
+       desc.pix_fmt = pix_fmt;\r
+       desc.planes.push_back( core::pixel_format_desc::plane(get_video_format_desc().width, get_video_format_desc().height, 4));\r
+       return create_frame(tag, desc);\r
+}\r
+void frame_mixer_device::set_image_transform(const core::image_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::image_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::set_image_transform(int index, const core::image_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::image_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::set_audio_transform(const core::audio_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::audio_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::set_audio_transform(int index, const core::audio_transform& transform, int mix_duration, const std::wstring& tween){impl_->set_transform<core::audio_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_image_transform(const std::function<core::image_transform(core::image_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::image_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_image_transform(int index, const std::function<core::image_transform(core::image_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::image_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_audio_transform(const std::function<core::audio_transform(core::audio_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::audio_transform>(transform, mix_duration, tween);}\r
+void frame_mixer_device::apply_audio_transform(int index, const std::function<core::audio_transform(core::audio_transform)>& transform, int mix_duration, const std::wstring& tween){impl_->apply_transform<core::audio_transform>(index, transform, mix_duration, tween);}\r
+void frame_mixer_device::reset_image_transform(int mix_duration, const std::wstring& tween){impl_->reset_transform<core::image_transform>(mix_duration, tween);}\r
+void frame_mixer_device::reset_image_transform(int index, int mix_duration, const std::wstring& tween){impl_->reset_transform<core::image_transform>(index, mix_duration, tween);}\r
+void frame_mixer_device::reset_audio_transform(int mix_duration, const std::wstring& tween){impl_->reset_transform<core::audio_transform>(mix_duration, tween);}\r
+void frame_mixer_device::reset_audio_transform(int index, int mix_duration, const std::wstring& tween){impl_->reset_transform<core::audio_transform>(index, mix_duration, tween);}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/frame_mixer_device.h b/core/mixer/frame_mixer_device.h
new file mode 100644 (file)
index 0000000..d72c42b
--- /dev/null
@@ -0,0 +1,78 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <core/consumer/frame/read_frame.h>\r
+#include <core/producer/frame/write_frame.h>\r
+#include <core/producer/frame/frame_factory.h>\r
+#include <core/producer/frame/pixel_format.h>\r
+\r
+#include "image/image_mixer.h"\r
+#include "audio/audio_mixer.h"\r
+\r
+#include <common/memory/safe_ptr.h>\r
+\r
+#include <boost/signals2.hpp>\r
+\r
+#include <functional>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class frame_mixer_device : public core::frame_factory\r
+{\r
+public:\r
+       typedef boost::signals2::signal<void(const safe_ptr<const core::read_frame>&)> output_t;\r
+        \r
+       boost::signals2::connection connect(const output_t::slot_type& subscriber);\r
+       \r
+       frame_mixer_device(const core::video_format_desc& format_desc);\r
+       frame_mixer_device(frame_mixer_device&& other); // nothrow\r
+               \r
+       void send(const std::map<int, safe_ptr<core::basic_frame>>& frames); // nothrow\r
+               \r
+       safe_ptr<core::write_frame> create_frame(void* tag, const core::pixel_format_desc& desc);               \r
+       safe_ptr<core::write_frame> create_frame(void* tag, size_t width, size_t height, core::pixel_format::type pix_fmt = core::pixel_format::bgra);                  \r
+       safe_ptr<core::write_frame> create_frame(void* tag, core::pixel_format::type pix_fmt = core::pixel_format::bgra);\r
+       \r
+       const core::video_format_desc& get_video_format_desc() const; // nothrow\r
+\r
+       void set_image_transform(const core::image_transform& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void set_image_transform(int index, const core::image_transform& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+\r
+       void set_audio_transform(const core::audio_transform& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void set_audio_transform(int index, const core::audio_transform& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       \r
+       void apply_image_transform(const std::function<core::image_transform(core::image_transform)>& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void apply_image_transform(int index, const std::function<core::image_transform(core::image_transform)>& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+\r
+       void apply_audio_transform(const std::function<core::audio_transform(core::audio_transform)>& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void apply_audio_transform(int index, const std::function<core::audio_transform(core::audio_transform)>& transform, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+\r
+       void reset_image_transform(int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void reset_image_transform(int index, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void reset_audio_transform(int mix_duration = 0, const std::wstring& tween = L"linear");\r
+       void reset_audio_transform(int index, int mix_duration = 0, const std::wstring& tween = L"linear");\r
+\r
+private:\r
+       struct implementation;\r
+       safe_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/device_buffer.cpp b/core/mixer/gpu/device_buffer.cpp
new file mode 100644 (file)
index 0000000..52c08ee
--- /dev/null
@@ -0,0 +1,106 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "device_buffer.h"\r
+\r
+#include <common/gl/gl_check.h>\r
+namespace caspar { namespace mixer {\r
+       \r
+GLenum FORMAT[] = {0, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_BGR, GL_BGRA};\r
+GLenum INTERNAL_FORMAT[] = {0, GL_LUMINANCE8, GL_LUMINANCE8_ALPHA8, GL_RGB8, GL_RGBA8};        \r
+\r
+struct device_buffer::implementation : boost::noncopyable\r
+{\r
+       GLuint id_;\r
+\r
+       const size_t width_;\r
+       const size_t height_;\r
+       const size_t stride_;\r
+\r
+public:\r
+       implementation(size_t width, size_t height, size_t stride) \r
+               : width_(width)\r
+               , height_(height)\r
+               , stride_(stride)\r
+       {       \r
+               GL(glGenTextures(1, &id_));\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));\r
+               GL(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));\r
+               GL(glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT[stride_], width_, height_, 0, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+               //CASPAR_LOG(trace) << "[device_buffer] allocated size:" << width*height*stride;        \r
+       }       \r
+\r
+       ~implementation()\r
+       {\r
+               GL(glDeleteTextures(1, &id_));\r
+       }\r
+       \r
+       void bind()\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+       }\r
+\r
+       void unbind()\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+       }\r
+\r
+       void read(host_buffer& source)\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+               source.unmap();\r
+               source.bind();\r
+               GL(glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
+               source.unbind();\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+       }\r
+       \r
+       void write(host_buffer& target)\r
+       {\r
+               GL(glBindTexture(GL_TEXTURE_2D, id_));\r
+               target.unmap();\r
+               target.bind();\r
+               GL(glReadPixels(0, 0, width_, height_, FORMAT[stride_], GL_UNSIGNED_BYTE, NULL));\r
+               target.unbind();\r
+               GL(glBindTexture(GL_TEXTURE_2D, 0));\r
+       }\r
+\r
+       void attach(int index)\r
+       {\r
+               GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + index, GL_TEXTURE_2D, id_, 0));\r
+       }\r
+};\r
+\r
+device_buffer::device_buffer(size_t width, size_t height, size_t stride) : impl_(new implementation(width, height, stride)){}\r
+size_t device_buffer::stride() const { return impl_->stride_; }\r
+size_t device_buffer::width() const { return impl_->width_; }\r
+size_t device_buffer::height() const { return impl_->height_; }\r
+void device_buffer::attach(int index){impl_->attach(index);}\r
+void device_buffer::bind(){impl_->bind();}\r
+void device_buffer::unbind(){impl_->unbind();}\r
+void device_buffer::read(host_buffer& source){impl_->read(source);}\r
+void device_buffer::write(host_buffer& target){impl_->write(target);}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/device_buffer.h b/core/mixer/gpu/device_buffer.h
new file mode 100644 (file)
index 0000000..d64a80c
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include "../gpu/host_buffer.h"\r
+\r
+#include <boost/noncopyable.hpp>\r
+\r
+#include <memory>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class device_buffer : boost::noncopyable\r
+{\r
+public:\r
+       device_buffer(size_t width, size_t height, size_t stride);\r
+       \r
+       size_t stride() const;  \r
+       size_t width() const;\r
+       size_t height() const;\r
+               \r
+       void bind();\r
+       void unbind();\r
+\r
+       void attach(int index);\r
+       void read(host_buffer& source);\r
+       void write(host_buffer& target);\r
+       \r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/gpu_read_frame.cpp b/core/mixer/gpu/gpu_read_frame.cpp
new file mode 100644 (file)
index 0000000..65b1e21
--- /dev/null
@@ -0,0 +1,55 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "gpu_read_frame.h"\r
+\r
+#include "../gpu/host_buffer.h"\r
+\r
+#include <common/gl/gl_check.h>\r
+\r
+namespace caspar { namespace mixer {\r
+                                                                                                                                                                                                                                                                                                                       \r
+struct gpu_read_frame::implementation : boost::noncopyable\r
+{\r
+       safe_ptr<const host_buffer> image_data_;\r
+       std::vector<short> audio_data_;\r
+\r
+public:\r
+       implementation(safe_ptr<const host_buffer>&& image_data, std::vector<short>&& audio_data) \r
+               : image_data_(std::move(image_data))\r
+               , audio_data_(std::move(audio_data)){}  \r
+};\r
+\r
+gpu_read_frame::gpu_read_frame(safe_ptr<const host_buffer>&& image_data, std::vector<short>&& audio_data) : impl_(new implementation(std::move(image_data), std::move(audio_data))){}\r
+\r
+const boost::iterator_range<const unsigned char*> gpu_read_frame::image_data() const\r
+{\r
+       if(!impl_->image_data_->data())\r
+               return boost::iterator_range<const unsigned char*>();\r
+       auto ptr = static_cast<const unsigned char*>(impl_->image_data_->data());\r
+       return boost::iterator_range<const unsigned char*>(ptr, ptr + impl_->image_data_->size());\r
+}\r
+const boost::iterator_range<const short*> gpu_read_frame::audio_data() const\r
+{\r
+       return boost::iterator_range<const short*>(impl_->audio_data_.data(), impl_->audio_data_.data() + impl_->audio_data_.size());\r
+}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/gpu_read_frame.h b/core/mixer/gpu/gpu_read_frame.h
new file mode 100644 (file)
index 0000000..4f84ecd
--- /dev/null
@@ -0,0 +1,49 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include "../gpu/host_buffer.h"        \r
+\r
+#include <core/consumer/frame/read_frame.h>\r
+\r
+#include <boost/noncopyable.hpp>\r
+#include <boost/range/iterator_range.hpp>\r
+\r
+#include <memory>\r
+#include <vector>\r
+\r
+#include <common/memory/safe_ptr.h>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class gpu_read_frame : public core::read_frame\r
+{\r
+public:\r
+       gpu_read_frame(safe_ptr<const host_buffer>&& image_data, std::vector<short>&& audio_data);\r
+\r
+       const boost::iterator_range<const unsigned char*> image_data() const;\r
+       const boost::iterator_range<const short*> audio_data() const;\r
+       \r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/gpu_write_frame.cpp b/core/mixer/gpu/gpu_write_frame.cpp
new file mode 100644 (file)
index 0000000..6e4b247
--- /dev/null
@@ -0,0 +1,97 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "gpu_write_frame.h"\r
+\r
+#include <core/producer/frame/pixel_format.h>\r
+\r
+#include "../image/image_mixer.h"\r
+#include "../audio/audio_mixer.h"\r
+\r
+#include "../gpu/host_buffer.h"\r
+\r
+#include <common/gl/gl_check.h>\r
+\r
+#include <boost/range/algorithm.hpp>\r
+\r
+namespace caspar { namespace mixer {\r
+                                                                                                                                                                                                                                                                                                                       \r
+struct gpu_write_frame::implementation : boost::noncopyable\r
+{                              \r
+       std::vector<safe_ptr<host_buffer>> buffers_;\r
+       std::vector<short> audio_data_;\r
+       const core::pixel_format_desc desc_;\r
+       int tag_;\r
+\r
+public:\r
+       implementation(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers) \r
+               : desc_(desc)\r
+               , buffers_(buffers)\r
+               , tag_(tag){}\r
+       \r
+       void accept(gpu_write_frame& self, core::frame_visitor& visitor)\r
+       {\r
+               visitor.begin(self);\r
+               visitor.visit(self);\r
+               visitor.end();\r
+       }\r
+\r
+       boost::iterator_range<unsigned char*> image_data(size_t index)\r
+       {\r
+               if(index >= buffers_.size() || !buffers_[index]->data())\r
+                       return boost::iterator_range<const unsigned char*>();\r
+               auto ptr = static_cast<unsigned char*>(buffers_[index]->data());\r
+               return boost::iterator_range<unsigned char*>(ptr, ptr+buffers_[index]->size());\r
+       }\r
+\r
+       const boost::iterator_range<const unsigned char*> image_data(size_t index) const\r
+       {\r
+               if(index >= buffers_.size() || !buffers_[index]->data())\r
+                       return boost::iterator_range<const unsigned char*>();\r
+               auto ptr = static_cast<const unsigned char*>(buffers_[index]->data());\r
+               return boost::iterator_range<const unsigned char*>(ptr, ptr+buffers_[index]->size());\r
+       }\r
+};\r
+       \r
+gpu_write_frame::gpu_write_frame(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers) : impl_(new implementation(tag, desc, buffers)){}\r
+gpu_write_frame::gpu_write_frame(gpu_write_frame&& other) : impl_(std::move(other.impl_)){}\r
+void gpu_write_frame::swap(gpu_write_frame& other){impl_.swap(other.impl_);}\r
+gpu_write_frame& gpu_write_frame::operator=(gpu_write_frame&& other)\r
+{\r
+       gpu_write_frame temp(std::move(other));\r
+       temp.swap(*this);\r
+       return *this;\r
+}\r
+void gpu_write_frame::accept(core::frame_visitor& visitor){impl_->accept(*this, visitor);}\r
+boost::iterator_range<unsigned char*> gpu_write_frame::image_data(size_t index){return impl_->image_data(index);}\r
+std::vector<short>& gpu_write_frame::audio_data() { return impl_->audio_data_; }\r
+const boost::iterator_range<const unsigned char*> gpu_write_frame::image_data(size_t index) const\r
+{\r
+       return boost::iterator_range<const unsigned char*>(impl_->image_data(index).begin(), impl_->image_data(index).end());\r
+}\r
+const boost::iterator_range<const short*> gpu_write_frame::audio_data() const\r
+{\r
+       return boost::iterator_range<const short*>(impl_->audio_data_.data(), impl_->audio_data_.data() + impl_->audio_data_.size());\r
+}\r
+int gpu_write_frame::tag() const {return impl_->tag_;}\r
+const core::pixel_format_desc& gpu_write_frame::get_pixel_format_desc() const{return impl_->desc_;}\r
+std::vector<safe_ptr<host_buffer>>& gpu_write_frame::get_plane_buffers(){return impl_->buffers_;}\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/gpu_write_frame.h b/core/mixer/gpu/gpu_write_frame.h
new file mode 100644 (file)
index 0000000..a4e408e
--- /dev/null
@@ -0,0 +1,66 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <common/memory/safe_ptr.h>\r
+#include <core/producer/frame/write_frame.h>\r
+#include <core/producer/frame/pixel_format.h>\r
+\r
+#include "../gpu/host_buffer.h"\r
+\r
+#include <boost/noncopyable.hpp>\r
+#include <boost/range/iterator_range.hpp>\r
+\r
+#include <memory>\r
+#include <vector>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class gpu_write_frame : public core::write_frame\r
+{\r
+public:        \r
+       explicit gpu_write_frame(int tag, const core::pixel_format_desc& desc, const std::vector<safe_ptr<host_buffer>>& buffers);\r
+       gpu_write_frame(gpu_write_frame&& other);\r
+       gpu_write_frame& operator=(gpu_write_frame&& other);\r
+       \r
+       void swap(gpu_write_frame& other);\r
+\r
+       const core::pixel_format_desc& get_pixel_format_desc() const;\r
+       std::vector<safe_ptr<host_buffer>>& get_plane_buffers();\r
+               \r
+       // core::write_frame\r
+       virtual boost::iterator_range<unsigned char*> image_data(size_t plane_index = 0);       \r
+       virtual std::vector<short>& audio_data();\r
+       \r
+       virtual const boost::iterator_range<const unsigned char*> image_data(size_t plane_index = 0) const;\r
+       virtual const boost::iterator_range<const short*> audio_data() const;\r
+\r
+       virtual void accept(core::frame_visitor& visitor);\r
+\r
+       virtual int tag() const;\r
+       \r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+typedef std::shared_ptr<gpu_write_frame> gpu_write_frame_impl_ptr;\r
+\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/host_buffer.cpp b/core/mixer/gpu/host_buffer.cpp
new file mode 100644 (file)
index 0000000..996abbd
--- /dev/null
@@ -0,0 +1,106 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "../gpu/host_buffer.h"\r
+\r
+#include <common/gl/gl_check.h>\r
+\r
+namespace caspar { namespace mixer {\r
+                                                                                                                                                                                                                                                                                                                               \r
+struct host_buffer::implementation : boost::noncopyable\r
+{      \r
+       GLuint pbo_;\r
+\r
+       const size_t size_;\r
+\r
+       void* data_;\r
+       GLenum usage_;\r
+       GLenum target_;\r
+\r
+public:\r
+       implementation(size_t size, usage_t usage) \r
+               : size_(size)\r
+               , data_(nullptr)\r
+               , pbo_(0)\r
+               , target_(usage == write_only ? GL_PIXEL_UNPACK_BUFFER : GL_PIXEL_PACK_BUFFER)\r
+               , usage_(usage == write_only ? GL_STREAM_DRAW : GL_STREAM_READ)\r
+       {\r
+               GL(glGenBuffers(1, &pbo_));\r
+               GL(glBindBuffer(target_, pbo_));\r
+               GL(glBufferData(target_, size_, NULL, usage_)); \r
+               GL(glBindBuffer(target_, 0));\r
+\r
+               if(!pbo_)\r
+                       BOOST_THROW_EXCEPTION(caspar_exception() << msg_info("Failed to allocate buffer."));\r
+\r
+               //CASPAR_LOG(trace) << "[host_buffer] allocated size:" << size_ << " usage: " << (usage == write_only ? "write_only" : "read_only");\r
+       }       \r
+\r
+       ~implementation()\r
+       {\r
+               GL(glDeleteBuffers(1, &pbo_));\r
+       }\r
+\r
+       void map()\r
+       {\r
+               if(data_)\r
+                       return;\r
+               \r
+               GL(glBindBuffer(target_, pbo_));\r
+               data_ = glMapBuffer(target_, usage_ == GL_STREAM_DRAW ? GL_WRITE_ONLY : GL_READ_ONLY);  \r
+               GL(glBindBuffer(target_, 0)); \r
+               if(!data_)\r
+                       BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Failed to map target_ OpenGL Pixel Buffer Object."));\r
+       }\r
+\r
+       void unmap()\r
+       {\r
+               if(!data_)\r
+                       return;\r
+               \r
+               GL(glBindBuffer(target_, pbo_));\r
+               GL(glUnmapBuffer(target_));     \r
+               data_ = nullptr;                \r
+               GL(glBindBuffer(target_, 0));\r
+       }\r
+\r
+       void bind()\r
+       {\r
+               GL(glBindBuffer(target_, pbo_));\r
+       }\r
+\r
+       void unbind()\r
+       {\r
+               GL(glBindBuffer(target_, 0));\r
+       }\r
+};\r
+\r
+host_buffer::host_buffer(size_t size, usage_t usage) : impl_(new implementation(size, usage)){}\r
+const void* host_buffer::data() const {return impl_->data_;}\r
+void* host_buffer::data() {return impl_->data_;}\r
+void host_buffer::map(){impl_->map();}\r
+void host_buffer::unmap(){impl_->unmap();}\r
+void host_buffer::bind(){impl_->bind();}\r
+void host_buffer::unbind(){impl_->unbind();}\r
+\r
+size_t host_buffer::size() const { return impl_->size_; }\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/host_buffer.h b/core/mixer/gpu/host_buffer.h
new file mode 100644 (file)
index 0000000..3d637b8
--- /dev/null
@@ -0,0 +1,51 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <boost/noncopyable.hpp>\r
+\r
+#include <memory>\r
+\r
+namespace caspar { namespace mixer {\r
+               \r
+class host_buffer : boost::noncopyable\r
+{\r
+public:\r
+       enum usage_t\r
+       {\r
+               write_only,\r
+               read_only\r
+       };\r
+       host_buffer(size_t size, usage_t usage);\r
+       \r
+       const void* data() const;\r
+       void* data();\r
+       size_t size() const;    \r
+       \r
+       void bind();\r
+       void unbind();\r
+       void unmap();\r
+       void map();\r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/ogl_device.cpp b/core/mixer/gpu/ogl_device.cpp
new file mode 100644 (file)
index 0000000..692bb3a
--- /dev/null
@@ -0,0 +1,102 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "ogl_device.h"\r
+\r
+#include <common/utility/assert.h>\r
+\r
+#include <Glee.h>\r
+#include <SFML/Window.hpp>\r
+\r
+#include <boost/foreach.hpp>\r
+\r
+namespace caspar { namespace mixer {\r
+\r
+ogl_device::ogl_device() : executor_(L"ogl_device")\r
+{\r
+       executor_.start();\r
+       invoke([=]\r
+       {\r
+               context_.reset(new sf::Context());\r
+               context_->SetActive(true);\r
+       });\r
+}\r
+\r
+ogl_device::~ogl_device()\r
+{\r
+       invoke([=]\r
+       {\r
+               BOOST_FOREACH(auto& pool, device_pools_)\r
+                       pool.clear();\r
+               BOOST_FOREACH(auto& pool, host_pools_)\r
+                       pool.clear();\r
+       });\r
+}\r
+                               \r
+safe_ptr<device_buffer> ogl_device::create_device_buffer(size_t width, size_t height, size_t stride)\r
+{\r
+       CASPAR_VERIFY(stride > 0 && stride < 5);\r
+       CASPAR_VERIFY(width > 0 && height > 0);\r
+       auto pool = &device_pools_[stride-1][((width << 16) & 0xFFFF0000) | (height & 0x0000FFFF)];\r
+       std::shared_ptr<device_buffer> buffer;\r
+       if(!pool->try_pop(buffer))              \r
+       {\r
+               executor_.invoke([&]\r
+               {\r
+                       buffer = std::make_shared<device_buffer>(width, height, stride);\r
+               });     \r
+       }\r
+               \r
+       return safe_ptr<device_buffer>(buffer.get(), [=](device_buffer*){pool->push(buffer);});\r
+}\r
+       \r
+safe_ptr<host_buffer> ogl_device::create_host_buffer(size_t size, host_buffer::usage_t usage)\r
+{\r
+       CASPAR_VERIFY(usage == host_buffer::write_only || usage == host_buffer::read_only);\r
+       CASPAR_VERIFY(size > 0);\r
+       auto pool = &host_pools_[usage][size];\r
+       std::shared_ptr<host_buffer> buffer;\r
+       if(!pool->try_pop(buffer))\r
+       {\r
+               executor_.invoke([&]\r
+               {\r
+                       buffer = std::make_shared<host_buffer>(size, usage);\r
+                       if(usage == host_buffer::write_only)\r
+                               buffer->map();\r
+                       else\r
+                               buffer->unmap();\r
+               });     \r
+       }\r
+\r
+       return safe_ptr<host_buffer>(buffer.get(), [=](host_buffer*)\r
+       {\r
+               executor_.begin_invoke([=]\r
+               {\r
+                       if(usage == host_buffer::write_only)\r
+                               buffer->map();\r
+                       else\r
+                               buffer->unmap();\r
+                       pool->push(buffer);\r
+               });\r
+       });\r
+}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/gpu/ogl_device.h b/core/mixer/gpu/ogl_device.h
new file mode 100644 (file)
index 0000000..de782ba
--- /dev/null
@@ -0,0 +1,74 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include "host_buffer.h"\r
+#include "device_buffer.h"\r
+\r
+#include <common/concurrency/executor.h>\r
+#include <common/memory/safe_ptr.h>\r
+\r
+#include <tbb/concurrent_unordered_map.h>\r
+#include <tbb/concurrent_queue.h>\r
+\r
+#include <boost/thread/future.hpp>\r
+\r
+#include <array>\r
+\r
+#include <SFML/Window/Context.hpp>\r
+\r
+namespace caspar { namespace mixer {\r
+\r
+class ogl_device\r
+{      \r
+       std::unique_ptr<sf::Context> context_;\r
+       \r
+       std::array<tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<device_buffer>>>, 4> device_pools_;\r
+       std::array<tbb::concurrent_unordered_map<size_t, tbb::concurrent_bounded_queue<std::shared_ptr<host_buffer>>>, 2> host_pools_;\r
+\r
+       executor executor_;\r
+\r
+       ogl_device();\r
+public:        \r
+       virtual ~ogl_device();\r
+\r
+       static safe_ptr<ogl_device> create()\r
+       {\r
+               static safe_ptr<ogl_device> instance(new ogl_device()); // Use the same ogl-device for all channels inorder to ensure that frames are always valid for all "context".\r
+               return instance;\r
+       }\r
+\r
+       template<typename Func>\r
+       auto begin_invoke(Func&& func) -> boost::unique_future<decltype(func())> // noexcept\r
+       {                       \r
+               return executor_.begin_invoke(std::forward<Func>(func));\r
+       }\r
+       \r
+       template<typename Func>\r
+       auto invoke(Func&& func) -> decltype(func())\r
+       {\r
+               return executor_.invoke(std::forward<Func>(func));\r
+       }\r
+               \r
+       safe_ptr<device_buffer> create_device_buffer(size_t width, size_t height, size_t stride);\r
+       safe_ptr<host_buffer> create_host_buffer(size_t size, host_buffer::usage_t usage);\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/image/image_kernel.cpp b/core/mixer/image/image_kernel.cpp
new file mode 100644 (file)
index 0000000..bd40c4a
--- /dev/null
@@ -0,0 +1,296 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "image_kernel.h"\r
+\r
+#include <common/exception/exceptions.h>\r
+#include <common/gl/gl_check.h>\r
+\r
+#include <core/video_format.h>\r
+#include <core/producer/frame/pixel_format.h>\r
+#include <core/producer/frame/image_transform.h>\r
+\r
+#include <Glee.h>\r
+\r
+#include <boost/noncopyable.hpp>\r
+\r
+#include <unordered_map>\r
+\r
+namespace caspar { namespace mixer {\r
+\r
+class shader_program : boost::noncopyable\r
+{\r
+       GLuint program_;\r
+public:\r
+\r
+       shader_program() : program_(0) {}\r
+       shader_program(shader_program&& other) : program_(other.program_){other.program_ = 0;}\r
+       shader_program(const std::string& vertex_source_str, const std::string& fragment_source_str) : program_(0)\r
+       {\r
+               GLint success;\r
+       \r
+               const char* vertex_source = vertex_source_str.c_str();\r
+                                               \r
+               auto vertex_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);\r
+                                       \r
+               GL(glShaderSourceARB(vertex_shader, 1, &vertex_source, NULL));\r
+               GL(glCompileShaderARB(vertex_shader));\r
+\r
+               GL(glGetObjectParameterivARB(vertex_shader, GL_OBJECT_COMPILE_STATUS_ARB, &success));\r
+               if (success == GL_FALSE)\r
+               {\r
+                       char info[2048];\r
+                       GL(glGetInfoLogARB(vertex_shader, sizeof(info), 0, info));\r
+                       GL(glDeleteObjectARB(vertex_shader));\r
+                       std::stringstream str;\r
+                       str << "Failed to compile vertex shader:" << std::endl << info << std::endl;\r
+                       BOOST_THROW_EXCEPTION(gl::gl_error() << msg_info(str.str()));\r
+               }\r
+                       \r
+               const char* fragment_source = fragment_source_str.c_str();\r
+                                               \r
+               auto fragmemt_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);\r
+                                       \r
+               GL(glShaderSourceARB(fragmemt_shader, 1, &fragment_source, NULL));\r
+               GL(glCompileShaderARB(fragmemt_shader));\r
+\r
+               GL(glGetObjectParameterivARB(fragmemt_shader, GL_OBJECT_COMPILE_STATUS_ARB, &success));\r
+               if (success == GL_FALSE)\r
+               {\r
+                       char info[2048];\r
+                       GL(glGetInfoLogARB(fragmemt_shader, sizeof(info), 0, info));\r
+                       GL(glDeleteObjectARB(fragmemt_shader));\r
+                       std::stringstream str;\r
+                       str << "Failed to compile fragment shader:" << std::endl << info << std::endl;\r
+                       BOOST_THROW_EXCEPTION(gl::gl_error() << msg_info(str.str()));\r
+               }\r
+                       \r
+               program_ = glCreateProgramObjectARB();\r
+                       \r
+               GL(glAttachObjectARB(program_, vertex_shader));\r
+               GL(glAttachObjectARB(program_, fragmemt_shader));\r
+\r
+               GL(glLinkProgramARB(program_));\r
+                       \r
+               GL(glDeleteObjectARB(vertex_shader));\r
+               GL(glDeleteObjectARB(fragmemt_shader));\r
+\r
+               GL(glGetObjectParameterivARB(program_, GL_OBJECT_LINK_STATUS_ARB, &success));\r
+               if (success == GL_FALSE)\r
+               {\r
+                       char info[2048];\r
+                       GL(glGetInfoLogARB(program_, sizeof(info), 0, info));\r
+                       GL(glDeleteObjectARB(program_));\r
+                       std::stringstream str;\r
+                       str << "Failed to link shader program:" << std::endl << info << std::endl;\r
+                       BOOST_THROW_EXCEPTION(gl::gl_error() << msg_info(str.str()));\r
+               }\r
+               GL(glUseProgramObjectARB(program_));\r
+               glUniform1i(glGetUniformLocation(program_, "plane[0]"), 0);\r
+               glUniform1i(glGetUniformLocation(program_, "plane[1]"), 1);\r
+               glUniform1i(glGetUniformLocation(program_, "plane[2]"), 2);\r
+               glUniform1i(glGetUniformLocation(program_, "plane[3]"), 3);\r
+       }\r
+\r
+       GLint get_location(const char* name)\r
+       {\r
+               GLint loc = glGetUniformLocation(program_, name);\r
+               return loc;\r
+       }\r
+\r
+       shader_program& operator=(shader_program&& other) \r
+       {\r
+               program_ = other.program_; \r
+               other.program_ = 0; \r
+               return *this;\r
+       }\r
+\r
+       ~shader_program()\r
+       {\r
+               glDeleteProgram(program_);\r
+       }\r
+\r
+       void use()\r
+       {       \r
+               GL(glUseProgramObjectARB(program_));            \r
+       }\r
+};\r
+\r
+GLubyte progressive_pattern[] = {\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,\r
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xFF, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};\r
+       \r
+GLubyte upper_pattern[] = {\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,\r
+       0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};\r
+               \r
+GLubyte lower_pattern[] = {\r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, \r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,\r
+       0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};\r
+\r
+struct image_kernel::implementation : boost::noncopyable\r
+{      \r
+       std::unordered_map<core::pixel_format::type, shader_program> shaders_;\r
+\r
+public:\r
+       std::unordered_map<core::pixel_format::type, shader_program>& shaders()\r
+       {\r
+               GL(glEnable(GL_POLYGON_STIPPLE));\r
+               GL(glEnable(GL_BLEND));\r
+               GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));  \r
+\r
+               if(shaders_.empty())\r
+               {\r
+               std::string common_vertex = \r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       gl_TexCoord[0] = gl_MultiTexCoord0;                                                                     "\r
+                       "       gl_FrontColor = gl_Color;                                                                                       "\r
+                       "       gl_Position = ftransform();                                                                                     "\r
+                       "}                                                                                                                                              ";\r
+\r
+               std::string common_fragment = \r
+                       "uniform sampler2D      plane[4];                                                                                       "\r
+                       "uniform float          gain;                                                                                           "\r
+                       "uniform bool           HD;                                                                                                     "\r
+                                                                                                                                                               \r
+                       // NOTE: YCbCr, ITU-R, http://www.intersil.com/data/an/an9717.pdf               \r
+                       // TODO: Support for more yuv formats might be needed.                                  \r
+                       "vec4 ycbcra_to_bgra_sd(float y, float cb, float cr, float a)                   "\r
+                       "{                                                                                                                                              "\r
+                       "       cb -= 0.5;                                                                                                                      "\r
+                       "       cr -= 0.5;                                                                                                                      "\r
+                       "       y = 1.164*(y-0.0625);                                                                                           "\r
+                       "                                                                                                                                               "\r
+                       "       vec4 color;                                                                                                                     "\r
+                       "       color.r = y + 1.596 * cr;                                                                                       "\r
+                       "       color.g = y - 0.813 * cr - 0.391 * cb;                                                          "\r
+                       "       color.b = y + 2.018 * cb;                                                                                       "\r
+                       "       color.a = a;                                                                                                            "\r
+                       "                                                                                                                                               "\r
+                       "       return color;                                                                                                           "\r
+                       "}                                                                                                                                              "                       \r
+                       "                                                                                                                                               "\r
+\r
+                       "vec4 ycbcra_to_bgra_hd(float y, float cb, float cr, float a)                   "\r
+                       "{                                                                                                                                              "\r
+                       "       cb -= 0.5;                                                                                                                      "\r
+                       "       cr -= 0.5;                                                                                                                      "\r
+                       "       y = 1.164*(y-0.0625);                                                                                           "\r
+                       "                                                                                                                                               "\r
+                       "       vec4 color;                                                                                                                     "\r
+                       "       color.r = y + 1.793 * cr;                                                                                       "\r
+                       "       color.g = y - 0.534 * cr - 0.213 * cb;                                                          "\r
+                       "       color.b = y + 2.115 * cb;                                                                                       "\r
+                       "       color.a = a;                                                                                                            "\r
+                       "                                                                                                                                               "\r
+                       "       return color;                                                                                                           "\r
+                       "}                                                                                                                                              "                       \r
+                       "                                                                                                                                               ";\r
+                       \r
+               shaders_[core::pixel_format::abgr] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       vec4 abgr = texture2D(plane[0], gl_TexCoord[0].st);                                     "\r
+                       "       gl_FragColor = abgr.argb * gain;                                                                        "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[core::pixel_format::argb]= shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "       \r
+                       "{                                                                                                                                              "\r
+                       "       vec4 argb = texture2D(plane[0], gl_TexCoord[0].st);                                     "\r
+                       "       gl_FragColor = argb.grab * gl_Color * gain;                                                     "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[core::pixel_format::bgra]= shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       vec4 bgra = texture2D(plane[0], gl_TexCoord[0].st);                                     "\r
+                       "       gl_FragColor = bgra.rgba * gl_Color * gain;                                                     "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[core::pixel_format::rgba] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       vec4 rgba = texture2D(plane[0], gl_TexCoord[0].st);                                     "\r
+                       "       gl_FragColor = rgba.bgra * gl_Color * gain;                                                     "\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[core::pixel_format::ycbcr] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       float y  = texture2D(plane[0], gl_TexCoord[0].st).r;                            "\r
+                       "       float cb = texture2D(plane[1], gl_TexCoord[0].st).r;                            "\r
+                       "       float cr = texture2D(plane[2], gl_TexCoord[0].st).r;                            "\r
+                       "       float a = 1.0;                                                                                                          "       \r
+                       "       if(HD)                                                                                                                          "\r
+                       "               gl_FragColor = ycbcra_to_bgra_hd(y, cb, cr, a) * gl_Color * gain;"\r
+                       "       else                                                                                                                            "\r
+                       "               gl_FragColor = ycbcra_to_bgra_sd(y, cb, cr, a) * gl_Color * gain;"\r
+                       "}                                                                                                                                              ");\r
+               \r
+               shaders_[core::pixel_format::ycbcra] = shader_program(common_vertex, common_fragment +\r
+\r
+                       "void main()                                                                                                                    "\r
+                       "{                                                                                                                                              "\r
+                       "       float y  = texture2D(plane[0], gl_TexCoord[0].st).r;                            "\r
+                       "       float cb = texture2D(plane[1], gl_TexCoord[0].st).r;                            "\r
+                       "       float cr = texture2D(plane[2], gl_TexCoord[0].st).r;                            "\r
+                       "       float a  = texture2D(plane[3], gl_TexCoord[0].st).r;                            "\r
+                       "       if(HD)                                                                                                                          "\r
+                       "               gl_FragColor = ycbcra_to_bgra_hd(y, cb, cr, a) * gl_Color * gain;"\r
+                       "       else                                                                                                                            "\r
+                       "               gl_FragColor = ycbcra_to_bgra_sd(y, cb, cr, a) * gl_Color * gain;"\r
+                       "}                                                                                                                                              ");\r
+               }\r
+               return shaders_;\r
+       }\r
+};\r
+\r
+image_kernel::image_kernel() : impl_(new implementation()){}\r
+\r
+void image_kernel::apply(const core::pixel_format_desc& pix_desc, const core::image_transform& transform)\r
+{\r
+       impl_->shaders()[pix_desc.pix_fmt].use();\r
+\r
+       GL(glUniform1f(impl_->shaders()[pix_desc.pix_fmt].get_location("gain"), static_cast<GLfloat>(transform.get_gain())));\r
+       GL(glUniform1i(impl_->shaders()[pix_desc.pix_fmt].get_location("HD"), pix_desc.planes.at(0).height > 700 ? 1 : 0));\r
+\r
+       if(transform.get_mode() == core::video_mode::upper)\r
+               glPolygonStipple(upper_pattern);\r
+       else if(transform.get_mode() == core::video_mode::lower)\r
+               glPolygonStipple(lower_pattern);\r
+       else\r
+               glPolygonStipple(progressive_pattern);\r
+}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/image/image_kernel.h b/core/mixer/image/image_kernel.h
new file mode 100644 (file)
index 0000000..e258249
--- /dev/null
@@ -0,0 +1,40 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <memory>\r
+\r
+#include <core/producer/frame/pixel_format.h>\r
+#include <core/producer/frame/image_transform.h>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class image_kernel\r
+{\r
+public:\r
+       image_kernel();\r
+       void apply(const core::pixel_format_desc& pix_desc, const core::image_transform& mode);\r
+\r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/image/image_mixer.cpp b/core/mixer/image/image_mixer.cpp
new file mode 100644 (file)
index 0000000..aa9741d
--- /dev/null
@@ -0,0 +1,196 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#include "../../stdafx.h"\r
+\r
+#include "image_mixer.h"\r
+#include "image_kernel.h"\r
+\r
+#include "../gpu/ogl_device.h"\r
+#include "../gpu/host_buffer.h"\r
+#include "../gpu/device_buffer.h"\r
+#include "../gpu/gpu_write_frame.h"\r
+\r
+#include <common/concurrency/executor.h>\r
+#include <common/exception/exceptions.h>\r
+#include <common/gl/gl_check.h>\r
+\r
+#include <core/producer/frame/image_transform.h>\r
+#include <core/producer/frame/pixel_format.h>\r
+#include <core/video_format.h>\r
+\r
+#include <boost/cast.hpp>\r
+\r
+#include <Glee.h>\r
+#include <SFML/Window/Context.hpp>\r
+\r
+#include <array>\r
+#include <unordered_map>\r
+\r
+namespace caspar { namespace mixer {\r
+               \r
+struct image_mixer::implementation : boost::noncopyable\r
+{                      \r
+       const core::video_format_desc format_desc_;\r
+       \r
+       std::stack<core::image_transform> transform_stack_;\r
+\r
+       GLuint fbo_;\r
+       std::array<std::shared_ptr<device_buffer>, 2> render_targets_;\r
+\r
+       std::shared_ptr<host_buffer> reading_;\r
+\r
+       image_kernel kernel_;\r
+\r
+       safe_ptr<ogl_device> context_;\r
+\r
+public:\r
+       implementation(const core::video_format_desc& format_desc) \r
+               : format_desc_(format_desc)\r
+               , context_(ogl_device::create())\r
+       {\r
+               context_->invoke([]\r
+               {\r
+                       if(!GLEE_VERSION_3_0)\r
+                               BOOST_THROW_EXCEPTION(not_supported() << msg_info("Missing OpenGL 3.0 support."));\r
+               });\r
+               \r
+               context_->begin_invoke([=]\r
+               {\r
+                       transform_stack_.push(core::image_transform());\r
+                       transform_stack_.top().set_mode(core::video_mode::progressive);\r
+\r
+                       GL(glEnable(GL_TEXTURE_2D));\r
+                       GL(glDisable(GL_DEPTH_TEST));           \r
+\r
+                       render_targets_[0] = context_->create_device_buffer(format_desc.width, format_desc.height, 4);\r
+                       render_targets_[1] = context_->create_device_buffer(format_desc.width, format_desc.height, 4);\r
+                       \r
+                       GL(glGenFramebuffers(1, &fbo_));                \r
+                       GL(glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo_));\r
+                       GL(glReadBuffer(GL_COLOR_ATTACHMENT0_EXT));\r
+\r
+                       reading_ = context_->create_host_buffer(format_desc_.size, host_buffer::read_only);\r
+               });\r
+       }\r
+\r
+       ~implementation()\r
+       {\r
+               glDeleteFramebuffersEXT(1, &fbo_);\r
+       }\r
+\r
+       void begin(const core::basic_frame& frame)\r
+       {\r
+               transform_stack_.push(transform_stack_.top()*frame.get_image_transform());\r
+       }\r
+               \r
+       void visit(core::write_frame& frame)\r
+       {\r
+               auto gpu_frame = boost::polymorphic_downcast<gpu_write_frame*>(&frame);\r
+               auto& desc = gpu_frame->get_pixel_format_desc();\r
+               auto& buffers = gpu_frame->get_plane_buffers();\r
+\r
+               auto transform = transform_stack_.top();\r
+               context_->begin_invoke([=]\r
+               {\r
+                       GL(glColor4d(1.0, 1.0, 1.0, transform.get_opacity()));\r
+                       GL(glViewport(0, 0, format_desc_.width, format_desc_.height));\r
+                       kernel_.apply(desc, transform);\r
+\r
+                       std::vector<safe_ptr<device_buffer>> device_buffers;\r
+                       for(size_t n = 0; n < buffers.size(); ++n)\r
+                       {\r
+                               auto texture = context_->create_device_buffer(desc.planes[n].width, desc.planes[n].height, desc.planes[n].channels);\r
+                               texture->read(*buffers[n]);\r
+                               device_buffers.push_back(texture);\r
+                       }\r
+\r
+                       for(size_t n = 0; n < buffers.size(); ++n)\r
+                       {\r
+                               GL(glActiveTexture(GL_TEXTURE0+n));\r
+                               device_buffers[n]->bind();\r
+                       }\r
+\r
+                       auto m_p = transform.get_key_translation();\r
+                       auto m_s = transform.get_key_scale();\r
+                       double w = static_cast<double>(format_desc_.width);\r
+                       double h = static_cast<double>(format_desc_.height);\r
+                       \r
+                       GL(glEnable(GL_SCISSOR_TEST));\r
+                       GL(glScissor(static_cast<size_t>(m_p[0]*w), static_cast<size_t>(m_p[1]*h), static_cast<size_t>(m_s[0]*w), static_cast<size_t>(m_s[1]*h)));\r
+                       \r
+                       auto f_p = transform.get_fill_translation();\r
+                       auto f_s = transform.get_fill_scale();\r
+                       \r
+                       glBegin(GL_QUADS);\r
+                               glTexCoord2d(0.0, 0.0); glVertex2d( f_p[0]        *2.0-1.0,      f_p[1]        *2.0-1.0);\r
+                               glTexCoord2d(1.0, 0.0); glVertex2d((f_p[0]+f_s[0])*2.0-1.0,  f_p[1]        *2.0-1.0);\r
+                               glTexCoord2d(1.0, 1.0); glVertex2d((f_p[0]+f_s[0])*2.0-1.0, (f_p[1]+f_s[1])*2.0-1.0);\r
+                               glTexCoord2d(0.0, 1.0); glVertex2d( f_p[0]        *2.0-1.0, (f_p[1]+f_s[1])*2.0-1.0);\r
+                       glEnd();\r
+                       GL(glDisable(GL_SCISSOR_TEST));\r
+               });\r
+       }\r
+\r
+       void end()\r
+       {\r
+               transform_stack_.pop();\r
+       }\r
+\r
+       boost::unique_future<safe_ptr<const host_buffer>> begin_pass()\r
+       {\r
+               return context_->begin_invoke([=]() -> safe_ptr<const host_buffer>\r
+               {\r
+                       reading_->map();\r
+                       render_targets_[0]->attach(0);\r
+                       GL(glClear(GL_COLOR_BUFFER_BIT));\r
+                       return safe_ptr<const host_buffer>(reading_);\r
+               });\r
+       }\r
+\r
+       void end_pass()\r
+       {\r
+               context_->begin_invoke([=]\r
+               {\r
+                       reading_ = context_->create_host_buffer(format_desc_.size, host_buffer::read_only);\r
+                       render_targets_[0]->write(*reading_);\r
+                       std::rotate(render_targets_.begin(), render_targets_.begin() + 1, render_targets_.end());\r
+               });\r
+       }\r
+               \r
+       std::vector<safe_ptr<host_buffer>> create_buffers(const core::pixel_format_desc& format)\r
+       {\r
+               std::vector<safe_ptr<host_buffer>> buffers;\r
+               std::transform(format.planes.begin(), format.planes.end(), std::back_inserter(buffers), [&](const core::pixel_format_desc::plane& plane)\r
+               {\r
+                       return context_->create_host_buffer(plane.size, host_buffer::write_only);\r
+               });\r
+               return buffers;\r
+       }\r
+};\r
+\r
+image_mixer::image_mixer(const core::video_format_desc& format_desc) : impl_(new implementation(format_desc)){}\r
+void image_mixer::begin(const core::basic_frame& frame){impl_->begin(frame);}\r
+void image_mixer::visit(core::write_frame& frame){impl_->visit(frame);}\r
+void image_mixer::end(){impl_->end();}\r
+boost::unique_future<safe_ptr<const host_buffer>> image_mixer::begin_pass(){   return impl_->begin_pass();}\r
+void image_mixer::end_pass(){impl_->end_pass();}\r
+std::vector<safe_ptr<host_buffer>> image_mixer::create_buffers(const core::pixel_format_desc& format){return impl_->create_buffers(format);}\r
+\r
+}}
\ No newline at end of file
diff --git a/core/mixer/image/image_mixer.h b/core/mixer/image/image_mixer.h
new file mode 100644 (file)
index 0000000..c0350fb
--- /dev/null
@@ -0,0 +1,55 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
+#pragma once\r
+\r
+#include <core/video_format.h>\r
+#include <core/producer/frame/frame_visitor.h>\r
+#include <core/producer/frame/pixel_format.h>\r
+\r
+#include "../gpu/host_buffer.h"\r
+\r
+#include <boost/noncopyable.hpp>\r
+#include <boost/thread/future.hpp>\r
+\r
+#include <memory>\r
+#include <vector>\r
+\r
+namespace caspar { namespace mixer {\r
+       \r
+class image_mixer : public core::frame_visitor, boost::noncopyable\r
+{\r
+public:\r
+       image_mixer(const core::video_format_desc& format_desc);\r
+       \r
+       virtual void begin(const core::basic_frame& frame);\r
+       virtual void visit(core::write_frame& frame);\r
+       virtual void end();\r
+\r
+       boost::unique_future<safe_ptr<const host_buffer>> begin_pass();\r
+       void end_pass();\r
+\r
+       std::vector<safe_ptr<host_buffer>> create_buffers(const core::pixel_format_desc& format);\r
+\r
+private:\r
+       struct implementation;\r
+       std::shared_ptr<implementation> impl_;\r
+};\r
+\r
+}}
\ No newline at end of file
index aa376d4c564b6b169ed50c04e21c93329edad767..cb272220d84c22a1dc3d313732049f3a1a27ca46 100644 (file)
@@ -21,7 +21,7 @@
 \r
 #include <common/memory/safe_ptr.h>\r
 \r
-#include <mixer/frame_mixer_device.h>\r
+#include <core/mixer/frame_mixer_device.h>\r
 \r
 struct AVCodecContext;\r
 \r
index 13f901ffc97075ec57aa8571ac697963889af755..f76a898e7b17d5af7e4a4603c50ddc1bc87e25f0 100644 (file)
@@ -25,9 +25,6 @@
     <ProjectReference Include="..\core\core.vcxproj">\r
       <Project>{79388c20-6499-4bf6-b8b9-d8c33d7d4ddd}</Project>\r
     </ProjectReference>\r
-    <ProjectReference Include="..\mixer\mixer.vcxproj">\r
-      <Project>{477e12a4-1b28-4ff7-b46d-76606bdd1891}</Project>\r
-    </ProjectReference>\r
     <ProjectReference Include="..\modules\flash\flash.vcxproj">\r
       <Project>{816deaba-3757-4306-afe0-c27cf96c4dea}</Project>\r
     </ProjectReference>\r
index f95cfb6fa00660db665289fe0177987af684ca35..6c72523e02fa94f7dcf64adcb1c945eacb64b916 100644 (file)
@@ -38,7 +38,7 @@
 #include <atlbase.h>\r
 #include <conio.h>\r
 \r
-#include <mixer/gpu/ogl_device.h>\r
+#include <core/mixer/gpu/ogl_device.h>\r
 \r
 #include <protocol/amcp/AMCPProtocolStrategy.h>\r
 \r
index 63d27459f427789ef7707a3a7eeeb1b5b0a6d83d..695b53cd3ee25fba8ec1dcdff6801951502a93c2 100644 (file)
@@ -34,9 +34,6 @@
     <ProjectReference Include="..\core\core.vcxproj">\r
       <Project>{79388c20-6499-4bf6-b8b9-d8c33d7d4ddd}</Project>\r
     </ProjectReference>\r
-    <ProjectReference Include="..\mixer\mixer.vcxproj">\r
-      <Project>{477e12a4-1b28-4ff7-b46d-76606bdd1891}</Project>\r
-    </ProjectReference>\r
     <ProjectReference Include="..\modules\bluefish\bluefish.vcxproj">\r
       <Project>{69313d25-9f54-4fc9-9872-628a4dd79464}</Project>\r
     </ProjectReference>\r