Merge "Remove the build dependency on Chromium."
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..90d6525
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,31 @@
+##  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
+##
+##  Use of this source code is governed by a BSD-style license
+##  that can be found in the LICENSE file in the root of the source
+##  tree. An additional intellectual property rights grant can be found
+##  in the file PATENTS.  All contributing project authors may
+##  be found in the AUTHORS file in the root of the source tree.
+cmake_minimum_required(VERSION 2.8)
+project(WEBMTOOLS)
+
+set(WEBMTOOLS_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
+# TODO(tomfinegan): The libwebm source directory must be configurable.
+set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../libwebm")
+# This is where LIBWEBM targets are built.
+set(LIBWEBM_BUILD_DIR "${CMAKE_BINARY_DIR}/libwebm_build")
+
+# Libwebm section.
+# Add the libwebm CMakeLists.txt and set the binary dir to allow access to
+# libwebm build output.
+add_subdirectory("${LIBWEBM_SRC_DIR}" "${LIBWEBM_BUILD_DIR}")
+include_directories("${LIBWEBM_SRC_DIR}"
+                    "${WEBMTOOLS_SRC_DIR}/shared")
+
+add_executable(webm_info
+  "${WEBMTOOLS_SRC_DIR}/shared/indent.cc"
+  "${WEBMTOOLS_SRC_DIR}/shared/indent.h"
+  "${WEBMTOOLS_SRC_DIR}/shared/webm_endian.cc"
+  "${WEBMTOOLS_SRC_DIR}/shared/webm_endian.h"
+  "${WEBMTOOLS_SRC_DIR}/webm_info/webm_info.cc")
+
+target_link_libraries(webm_info LINK_PUBLIC webm)
diff --git a/alpha_encoder/alpha_encoder.cc b/alpha_encoder/alpha_encoder.cc
index 3cb425b..4402ab1 100644
--- a/alpha_encoder/alpha_encoder.cc
+++ b/alpha_encoder/alpha_encoder.cc
@@ -85,22 +85,22 @@
 
 bool Encode(const std::string& vpxenc_cmd,
             const std::string& vpxenc_options,
-            int w, int h) {
+            int w, int h, std::string codec) {
   // TODO(vigneshv): For now, we force the keyframe intervals to a static value
   // on both the encodes so that the keyframes are aligned. Ideal way to do
   // this is to encode the first file, parse it to determine key frames and
   // pass that list to vpxenc for the second file.
   std::ostringstream encode_cmd;
   encode_cmd << vpxenc_cmd << " --width=" << w << " --height=" << h
-             << " --kf-min-dist=150 --kf-max-dist=150 " << vpxenc_options
-             << " -o video.out video.in";
+             << " --codec=" << codec << " --kf-min-dist=150 --kf-max-dist=150 "
+             << vpxenc_options << " -o video.out video.in";
   fprintf(stderr, "Running %s\n", encode_cmd.str().c_str());
   if (system(encode_cmd.str().c_str()))
     return false;
   encode_cmd.str(std::string());
   encode_cmd << vpxenc_cmd << " --width=" << w << " --height=" << h
-             << " --kf-min-dist=150 --kf-max-dist=150 " << vpxenc_options
-             << " -o alpha.out alpha.in";
+             << " --codec=" << codec << " --kf-min-dist=150 --kf-max-dist=150 "
+             << vpxenc_options << " -o alpha.out alpha.in";
   fprintf(stderr, "Running %s\n", encode_cmd.str().c_str());
   if (system(encode_cmd.str().c_str()))
     return false;
@@ -118,6 +118,7 @@
   printf("  -o                output file (webm with alpha)\n");
   printf("  -w                width of the input file\n");
   printf("  -h                height of the input file\n");
+  printf("  -c                codec (vp8 or vp9). default is vp8\n");
   printf("  -b                absolute/relative path of vpxenc binary. "
          "default is ../../libvpx/vpxenc\n");
   printf(" [vpxenc_options]   options to be passed to vpxenc. these options"
@@ -175,7 +176,8 @@
                 mkvparser::MkvReader* reader_alpha,
                 mkvmuxer::Segment* muxer_segment,
                 mkvparser::Segment** parser_segment,
-                mkvparser::Segment** parser_segment_alpha) {
+                mkvparser::Segment** parser_segment_alpha,
+                std::string codec) {
   long long pos = 0;
   mkvparser::EBMLHeader ebml_header;
   ebml_header.Parse(reader, pos);
@@ -249,6 +251,8 @@
     return false;
   }
 
+  video->set_codec_id((codec == "vp9") ?
+      mkvmuxer::Tracks::kVp9CodecId : mkvmuxer::Tracks::kVp8CodecId);
   if (track_name)
     video->set_name(track_name);
 
@@ -355,6 +359,7 @@
   const char* output = NULL;
   std::string vpxenc_cmd = "../../libvpx/vpxenc";
   std::string vpxenc_options = "";
+  std::string codec = "vp8";
   long w = -1;
   long h = -1;
   int i;
@@ -376,6 +381,8 @@
       h = strtol(argv[++i], &end, 10);
     } else if (!strcmp("-b", argv[i]) && i < argc_check) {
       vpxenc_cmd = argv[++i];
+    } else if (!strcmp("-c", argv[i]) && i < argc_check) {
+      codec = argv[++i];
     } else {
       break;
     }
@@ -391,6 +398,11 @@
     Usage();
     return EXIT_FAILURE;
   }
+  if (codec != "vp8" && codec != "vp9") {
+    fprintf(stderr, "Invalid codec: '%s'. Has to be one of 'vp8' or 'vp9'.\n",
+            codec.c_str());
+    return EXIT_FAILURE;
+  }
   if (w < 16 || h < 16) {
     fprintf(stderr, "Invalid resolution: %ldx%ld", w, h);
     return EXIT_FAILURE;
@@ -404,10 +416,10 @@
   mkvparser::Segment* parser_segment_alpha = NULL;
 
   if (!CreateInputFiles(input, w, h) ||
-      !Encode(vpxenc_cmd, vpxenc_options, w, h) ||
+      !Encode(vpxenc_cmd, vpxenc_options, w, h, codec) ||
       !Init(output, &writer, &muxer_segment, &reader, &reader_alpha) ||
       !WriteTrack(&reader, &reader_alpha, &muxer_segment,
-                  &parser_segment, &parser_segment_alpha) ||
+                  &parser_segment, &parser_segment_alpha, codec) ||
       !WriteClusters(&reader, &reader_alpha, &muxer_segment,
                      parser_segment, parser_segment_alpha) ||
       !Cleanup(&writer, &reader, &reader_alpha, &muxer_segment,
diff --git a/vpx_ios/VPXExample/VPXExample.xcodeproj/project.pbxproj b/vpx_ios/VPXExample/VPXExample.xcodeproj/project.pbxproj
index 14bf209..6504bf8 100644
--- a/vpx_ios/VPXExample/VPXExample.xcodeproj/project.pbxproj
+++ b/vpx_ios/VPXExample/VPXExample.xcodeproj/project.pbxproj
@@ -482,6 +482,7 @@
 			buildSettings = {
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
+				ENABLE_BITCODE = YES;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
 					"$(PROJECT_DIR)/../../../frameworks",
@@ -489,6 +490,7 @@
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "VPXExample-Prefix.pch";
 				INFOPLIST_FILE = "VPXExample-Info.plist";
+				LD_NO_PIE = NO;
 				ONLY_ACTIVE_ARCH = NO;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				VALID_ARCHS = armv7;
@@ -501,6 +503,7 @@
 			buildSettings = {
 				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
 				ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
+				ENABLE_BITCODE = YES;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
 					"$(PROJECT_DIR)/../../../frameworks",
@@ -508,6 +511,7 @@
 				GCC_PRECOMPILE_PREFIX_HEADER = YES;
 				GCC_PREFIX_HEADER = "VPXExample-Prefix.pch";
 				INFOPLIST_FILE = "VPXExample-Info.plist";
+				LD_NO_PIE = NO;
 				ONLY_ACTIVE_ARCH = NO;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				VALID_ARCHS = armv7;
diff --git a/vpx_ios/VPXExample/ViewController.mm b/vpx_ios/VPXExample/ViewController.mm
index a186651..e4fc7c5 100644
--- a/vpx_ios/VPXExample/ViewController.mm
+++ b/vpx_ios/VPXExample/ViewController.mm
@@ -37,8 +37,8 @@
                       action:@selector(downloadTestFile)
             forControlEvents:UIControlEventTouchUpInside];
   _playButton.enabled = NO;
-  cacheDirectoryPath_ = [NSSearchPathForDirectoriesInDomains(
-      NSCachesDirectory, NSUserDomainMask, YES) lastObject];
+  cacheDirectoryPath_ = [NSURL URLWithString:[NSSearchPathForDirectoriesInDomains(
+      NSCachesDirectory, NSUserDomainMask, YES) lastObject]];
   [self
       appendToOutputTextView:[NSString stringWithFormat:@"libvpx: %s %s",
                                                         VERSION_STRING_NOSP,
diff --git a/webm_info/webm_info.cc b/webm_info/webm_info.cc
index 5a7ad6a..324d7f8 100644
--- a/webm_info/webm_info.cc
+++ b/webm_info/webm_info.cc
@@ -499,27 +499,6 @@
   return true;
 }
 
-// This function reads the length of the first frame from a set of packed
-// frames. It works its way backward from the last frame by reading the lengths
-// of each frame and subtracting it till the first frame is reached.
-void read_frame_length(const unsigned char* data, int size, int* frame_length,
-                       int* size_length) {
-  int value = 0;
-  *size_length = 0;
-  do {
-    int index;
-    size -= value + *size_length;
-    index = size - 1;
-    value = 0;
-    do {
-      value <<= 7;
-      value |= (data[index] & 0x7F);
-    } while (!(data[index--] >> 7));
-    *size_length = size - 1 - index;
-  } while (value + *size_length < size);
-  *frame_length = value;
-}
-
 // libvpx reference: vp9/vp9_dx_iface.c
 void ParseSuperframeIndex(const uint8* data, size_t data_sz,
                           uint32 sizes[8], int* count) {