Merge "webm_encoder: Add audio support to WebmEncoder." into v2
diff --git a/client_encoder/client_encoder.gyp b/client_encoder/client_encoder.gyp
new file mode 100644
index 0000000..7c387a3
--- /dev/null
+++ b/client_encoder/client_encoder.gyp
@@ -0,0 +1,135 @@
+{
+  'targets': [
+    {
+      'target_name': 'client_encoder',
+      'type': 'executable',
+      'defines': [
+      ],
+      'include_dirs': [
+        '../',
+        '../third_party',
+        '../third_party/boost/include',
+        '../third_party/libogg',
+        '../third_party/libvorbis',
+        '../third_party/libvpx/vpx',
+        '../third_party/libyuv/include',
+      ],
+      'sources': [
+        'audio_encoder.cc',
+        'audio_encoder.h',
+        'basictypes.h',
+        'buffer_pool-inl.h',
+        'buffer_pool.h',
+        'buffer_util.cc',
+        'buffer_util.h',
+        'client_encoder_base.h',
+        'client_encoder_main.cc',
+        'data_sink.h',
+        'http_uploader.cc',
+        'http_uploader.h',
+        'video_encoder.cc',
+        'video_encoder.h',
+        'vorbis_encoder.cc',
+        'vorbis_encoder.h',
+        'vpx_encoder.cc',
+        'vpx_encoder.h',
+        'webm_buffer_parser.cc',
+        'webm_buffer_parser.h',
+        'webm_encoder.cc',
+        'webm_encoder.h',
+        'webm_mux.cc',
+        'webm_mux.h',
+      ],
+      'conditions': [
+        ['OS=="linux"', {
+          'defines': [
+          ],
+          'include_dirs': [
+          ],
+        }],
+        ['OS=="win"', {
+          'default_configuration': 'Debug',
+          'dependencies': [
+            'win/direct_show_base_classes.gyp:direct_show_base_classes',
+          ],
+          'msvs_configuration_attributes': {
+            'OutputDirectory': '$(ProjectDir)../../exe/webmlive/$(ProjectName)/$(PlatformName)/$(ConfigurationName)/',
+            'IntermediateDirectory': '$(ProjectDir)../../obj/webmlive/$(ProjectName)/$(PlatformName)/$(ConfigurationName)/',
+          },
+          'msbuild_configuration_attributes': {
+            'OutputDirectory': '$(ProjectDir)../../exe/webmlive/$(ProjectName)/$(Platform)/$(Configuration)/',
+            'IntermediateDirectory': '$(ProjectDir)../../obj/webmlive/$(ProjectName)/$(Platform)/$(Configuration)/',
+          },
+          'configurations': {
+            'Debug': {
+              'msvs_settings': {
+                'VCCLCompilerTool': {
+                  'Optimization': '0',
+                  'PreprocessorDefinitions': [
+                    '_DEBUG',
+                    'CURL_STATICLIB',
+                    'BOOST_NO_EXCEPTIONS',
+                    'WIN32',
+                  ],
+                  'RuntimeLibrary': '1',
+                },
+                'VCLinkerTool': {
+                  'AdditionalLibraryDirectories': '../third_party/boost/win/x86/debug',
+                },
+              },
+            },
+            'Release': {
+              'msvs_settings': {
+                'VCCLCompilerTool': {
+                  'Optimization': '2',
+                  'PreprocessorDefinitions': [
+                    'BOOST_NO_EXCEPTIONS',
+                    'NDEBUG',
+                    'CURL_STATICLIB',
+                    'WIN32',
+                  ],
+                  'RuntimeLibrary': '0',
+                },
+                'VCLinkerTool': {
+                  'AdditionalLibraryDirectories': '../third_party/boost/win/x86/release',
+                },
+              },
+            },
+          },
+          'msvs_disabled_warnings': [
+            4244, 4995, 4996
+          ],
+          'msvs_settings': {
+            'VCCLCompilerTool': {
+              'DebugInformationFormat': '1',  # C7 compatible debug info
+              'WarningLevel': '4',
+              'WarnAsError': 'false',
+            },
+            'VCLinkerTool': {
+              'AdditionalDependencies': ['advapi32.lib'],
+              'SubSystem': '1',  # Set /SUBSYSTEM:CONSOLE
+            },
+          },
+          'sources': [
+            'win/audio_sink_filter.cc',
+            'win/audio_sink_filter.h',
+            'win/build_config_win.cc',
+            'win/dshow_util.cc',
+            'win/dshow_util.h',
+            'win/media_source_dshow.cc',
+            'win/media_source_dshow.h',
+            'win/media_type_dshow.cc',
+            'win/media_type_dshow.h',
+            'win/video_sink_filter.cc',
+            'win/video_sink_filter.h',
+            'win/webm_guids.cc',
+            'win/webm_guids.h',
+          ],
+        }, { # OS != "win",
+          'defines': [
+          ],
+        }],
+      ],
+    },
+  ],
+}
diff --git a/client_encoder/win/direct_show_base_classes.gyp b/client_encoder/win/direct_show_base_classes.gyp
new file mode 100644
index 0000000..8f94836
--- /dev/null
+++ b/client_encoder/win/direct_show_base_classes.gyp
@@ -0,0 +1,138 @@
+# Shamelessly copied from WebRTC.

+{

+  'targets': [

+    {

+      'target_name': 'direct_show_base_classes',

+      'type': 'static_library',

+      'variables': {

+        # Path needed to build the Direct Show base classes on Windows. The

+        # code is included in the Windows SDK.

+        'direct_show_dir':

+          'C:/Program Files/Microsoft SDKs/Windows/v7.1/Samples/multimedia/directshow/baseclasses/',

+      },

+      'defines!': [

+        'NOMINMAX',

+      ],

+      'include_dirs': [

+        '<(direct_show_dir)',

+      ],

+      'direct_dependent_settings': {

+        'include_dirs': [

+          '<(direct_show_dir)',

+          '<(direct_show_dir)/..',

+        ],

+      },

+      'sources': [

+        '<(direct_show_dir)amextra.cpp',

+        '<(direct_show_dir)amextra.h',

+        '<(direct_show_dir)amfilter.cpp',

+        '<(direct_show_dir)amfilter.h',

+        '<(direct_show_dir)amvideo.cpp',

+        '<(direct_show_dir)arithutil.cpp',

+        '<(direct_show_dir)cache.h',

+        '<(direct_show_dir)checkbmi.h',

+        '<(direct_show_dir)combase.cpp',

+        '<(direct_show_dir)combase.h',

+        '<(direct_show_dir)cprop.cpp',

+        '<(direct_show_dir)cprop.h',

+        '<(direct_show_dir)ctlutil.cpp',

+        '<(direct_show_dir)ctlutil.h',

+        '<(direct_show_dir)ddmm.cpp',

+        '<(direct_show_dir)ddmm.h',

+        '<(direct_show_dir)dllentry.cpp',

+        '<(direct_show_dir)dllsetup.cpp',

+        '<(direct_show_dir)dllsetup.h',

+        '<(direct_show_dir)dxmperf.h',

+        '<(direct_show_dir)fourcc.h',

+        '<(direct_show_dir)measure.h',

+        '<(direct_show_dir)msgthrd.h',

+        '<(direct_show_dir)mtype.cpp',

+        '<(direct_show_dir)mtype.h',

+        '<(direct_show_dir)outputq.cpp',

+        '<(direct_show_dir)outputq.h',

+        '<(direct_show_dir)perflog.cpp',

+        '<(direct_show_dir)perflog.h',

+        '<(direct_show_dir)perfstruct.h',

+        '<(direct_show_dir)pstream.cpp',

+        '<(direct_show_dir)pstream.h',

+        '<(direct_show_dir)pullpin.cpp',

+        '<(direct_show_dir)pullpin.h',

+        '<(direct_show_dir)refclock.cpp',

+        '<(direct_show_dir)refclock.h',

+        '<(direct_show_dir)reftime.h',

+        '<(direct_show_dir)renbase.cpp',

+        '<(direct_show_dir)renbase.h',

+        '<(direct_show_dir)schedule.cpp',

+        '<(direct_show_dir)schedule.h',

+        '<(direct_show_dir)seekpt.cpp',

+        '<(direct_show_dir)seekpt.h',

+        '<(direct_show_dir)source.cpp',

+        '<(direct_show_dir)source.h',

+        '<(direct_show_dir)streams.h',

+        '<(direct_show_dir)strmctl.cpp',

+        '<(direct_show_dir)strmctl.h',

+        '<(direct_show_dir)sysclock.cpp',

+        '<(direct_show_dir)sysclock.h',

+        '<(direct_show_dir)transfrm.cpp',

+        '<(direct_show_dir)transfrm.h',

+        '<(direct_show_dir)transip.cpp',

+        '<(direct_show_dir)transip.h',

+        '<(direct_show_dir)videoctl.cpp',

+        '<(direct_show_dir)videoctl.h',

+        '<(direct_show_dir)vtrans.cpp',

+        '<(direct_show_dir)vtrans.h',

+        '<(direct_show_dir)winctrl.cpp',

+        '<(direct_show_dir)winctrl.h',

+        '<(direct_show_dir)winutil.cpp',

+        '<(direct_show_dir)winutil.h',

+        '<(direct_show_dir)wxdebug.cpp',

+        '<(direct_show_dir)wxdebug.h',

+        '<(direct_show_dir)wxlist.cpp',

+        '<(direct_show_dir)wxlist.h',

+        '<(direct_show_dir)wxutil.cpp',

+        '<(direct_show_dir)wxutil.h',

+      ],

+      'conditions': [

+        ['OS=="win"', {

+          'msvs_configuration_attributes': {

+            'OutputDirectory': '$(ProjectDir)../../../exe/webmlive/$(ProjectName)/$(PlatformName)/$(ConfigurationName)/',

+            'IntermediateDirectory': '$(ProjectDir)../../../obj/webmlive/$(ProjectName)/$(PlatformName)/$(ConfigurationName)/',

+          },

+          'msbuild_configuration_attributes': {

+            'OutputDirectory': '$(ProjectDir)../../../exe/webmlive/$(ProjectName)/$(Platform)/$(Configuration)/',

+            'IntermediateDirectory': '$(ProjectDir)../../../obj/webmlive/$(ProjectName)/$(Platform)/$(Configuration)/',

+          },

+          'default_configuration': 'Debug',

+          'configurations': {

+            'Debug': {

+              'msvs_settings': {

+                'VCCLCompilerTool': {

+                  'Optimization': '0',

+                  'PreprocessorDefinitions': [

+                    '_DEBUG',

+                    'WIN32',

+                  ],

+                  'RuntimeLibrary': '1',

+                },

+              },

+            },

+            'Release': {

+              'msvs_settings': {

+                'VCCLCompilerTool': {

+                  'Optimization': '2',

+                  'PreprocessorDefinitions': [

+                    'NDEBUG',

+                    'WIN32',

+                  ],

+                  'RuntimeLibrary': '0',

+                },

+              },

+            },

+          },

+        }],

+      ],

+    },

+  ],

+}

+

+

diff --git a/tools/generate_msvc_projects.bat b/tools/generate_msvc_projects.bat
new file mode 100644
index 0000000..05e1b75
--- /dev/null
+++ b/tools/generate_msvc_projects.bat
@@ -0,0 +1,140 @@
+@echo off

+setlocal

+

+REM Copyright (c) 2013 The WebM project authors. All Rights Reserved.

+REM

+REM Use of this source code is governed by a BSD-style license

+REM that can be found in the LICENSE file in the root of the source

+REM tree. An additional intellectual property rights grant can be found

+REM in the file PATENTS.  All contributing project authors may

+REM be found in the AUTHORS file in the root of the source tree.

+

+REM Generates webmlive MSVC projects. Note that GYP uses settings in the

+REM environment to control project file generation, and that they're going

+REM to be overridden here to force output of projects and solutions for

+REM multiple versions of MSVC.

+

+REM Make sure we are in the right place.

+IF NOT %~0==tools\generate_msvc_projects.bat (

+  echo This script must be run from your webmlive root.

+  REM Windows helpfully defines error code 10: ERROR_BAD_ENVIRONMENT

+  exit /B 10

+)

+

+REM Make sure GYP is defined, and that it points at a file that exists.

+IF NOT DEFINED GYP (

+  CALL :die "GYP environment variable not defined"

+)

+IF NOT EXIST %GYP% (

+  CALL :die "%GYP% does not exist"

+)

+

+

+set PERL=perl.exe

+REM Make sure perl.exe is in PATH and exists, since it's required.

+for %%X in (%PERL%) do (set PERL_FOUND=%%~$PATH:X)

+if NOT defined PERL_FOUND (

+  CALL :die "%PERL% must be in your PATH"

+)

+

+set original_dir=%cd%

+set dshow_name="direct_show_base_classes"

+set encoder_name="client_encoder"

+

+REM Make sure only MSVC projects are generated-- not supporting ninja

+REM in webmlive, for example.

+set GYP_GENERATORS=msvs

+

+REM Remove existing files

+del client_encoder\*.vcproj

+del client_encoder\*.vcxproj

+del client_encoder\*.vcxproj.filters

+del client_encoder\*.sln

+del client_encoder\win\*.vcproj

+del client_encoder\win\*.vcxproj

+del client_encoder\win\*.vcxproj.filters

+del client_encoder\win\*.sln

+

+REM TODO(tomfinegan): Move duped code into a function(s).

+

+REM

+REM Generate the MSVC 2008 projects and solutions.

+REM

+set GYP_MSVS_VERSION=2008

+chdir client_encoder

+

+REM Generate the projects and solutions.

+CALL %GYP%

+

+REM Rename the client_encoder files.

+CALL :RenameMSVCFiles %encoder_name% 2008 vcproj

+CALL :RenameMSVCFiles %encoder_name% 2008 sln

+

+REM Correct project file names in the client_encoder solution file.

+%PERL% -pi.orig -e "s/.vcproj/_2008.vcproj/g" %renamed_file%

+REM A backup file is stored because in place edits seem to trigger

+REM permissions issues on Win 7. Delete it.

+del %renamed_file%.orig

+

+REM Do the same for the direct_show_base_classes standalone solution.

+chdir win

+CALL :RenameMSVCFiles %dshow_name% 2008 vcproj

+CALL :RenameMSVCFiles %dshow_name% 2008 sln

+%PERL% -pi.orig -e "s/.vcproj/_2008.vcproj/g" %renamed_file%

+del %renamed_file%.orig

+

+REM

+REM Generate the MSVC 2010 project and solutions.

+REM

+set GYP_MSVS_VERSION=2010

+chdir %original_dir%\client_encoder

+

+REM Generate the projects and solutions.

+CALL %GYP%

+

+REM Rename the client_encoder files, and patch references to the vcxproj.

+CALL :RenameMSVCFiles %encoder_name% 2010 vcxproj

+%PERL% -pi.orig -e "s/.vcxproj/_2010.vcxproj/g" %renamed_file%

+del %renamed_file%.orig

+CALL :RenameMSVCFiles %encoder_name% 2010 sln

+%PERL% -pi.orig -e "s/.vcxproj/_2010.vcxproj/g" %renamed_file%

+del %renamed_file%.orig

+

+REM Do the same for the direct_show_base_classes standalone solution.

+chdir win

+CALL :RenameMSVCFiles %dshow_name% 2010 vcxproj

+CALL :RenameMSVCFiles %dshow_name% 2010 sln

+%PERL% -pi.orig -e "s/.vcxproj/_2010.vcxproj/g" %renamed_file%

+del %renamed_file%.orig

+

+chdir %original_dir%

+echo Done.

+goto :EOF

+

+REM Utility function used to rename project and solution files so that

+REM their names contain the year of the MSVC release they are intended

+REM for use within.

+:RenameMSVCFiles

+  set name=%~1

+  set year=%~2

+  set ext=%~3

+  set original=%name%.%ext%

+  set renamed=%name%_%year%.%ext%

+  rename %original% %renamed%

+  endlocal & set renamed_file=%renamed%

+  IF NOT EXIST %renamed_file% (

+    CALL :die "%renamed_file% does not exist"

+  )

+goto :EOF

+

+:die

+  set message=%~1

+  IF NOT ""=="%message%" (

+    echo ERROR: %message%, giving up.

+  ) ELSE (

+    echo ERROR: unspecified error, giving up.

+  )

+  endlocal

+  echo Ignore the syntax error: it's how this script kills itself.

+  () creates syntax error, and terminates script.

+goto :EOF