Bug 842243 - Part 1: Add ContainerWriter.h; Base class of media container writer. r=roc
authorShelly Lin <slin@mozilla.com>
Fri, 17 May 2013 18:50:58 +0800
changeset 146109 6e7e12d2fcf41d742dbfac31e8e59fec5055490a
parent 146108 e59ac8e0e4104e5547f668b77a3f3e3fbde912bd
child 146110 f0c287193841e654b87196c0d2f53c9613db99d2
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs842243
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 842243 - Part 1: Add ContainerWriter.h; Base class of media container writer. r=roc
content/media/encoder/ContainerWriter.h
content/media/encoder/moz.build
content/media/moz.build
new file mode 100644
--- /dev/null
+++ b/content/media/encoder/ContainerWriter.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef ContainerWriter_h_
+#define ContainerWriter_h_
+
+#include "nsTArray.h"
+#include "nsAutoPtr.h"
+
+namespace mozilla {
+/**
+ * ContainerWriter packs encoded track data into a specific media container.
+ */
+class ContainerWriter {
+public:
+  ContainerWriter()
+    : mInitialized(false)
+  {}
+  virtual ~ContainerWriter() {}
+
+  enum {
+    END_OF_STREAM = 1 << 0
+  };
+
+  /**
+   * Writes encoded track data from aBuffer to a packet, and insert this packet
+   * into the internal stream of container writer. aDuration is the playback
+   * duration of this packet in number of samples. aFlags is true with
+   * END_OF_STREAM if this is the last packet of track.
+   * Currently, WriteEncodedTrack doesn't support multiple tracks.
+   */
+  virtual nsresult WriteEncodedTrack(const nsTArray<uint8_t>& aBuffer,
+                                     int aDuration, uint32_t aFlags = 0) = 0;
+
+  enum {
+    FLUSH_NEEDED = 1 << 0
+  };
+
+  /**
+   * Copies the final container data to a buffer if it has accumulated enough
+   * packets from WriteEncodedTrack. This buffer of data is appended to
+   * aOutputBufs, and existing elements of aOutputBufs should not be modified.
+   * aFlags is true with FLUSH_NEEDED will force OggWriter to flush an ogg page
+   * even it is not full, and copy these container data to a buffer for
+   * aOutputBufs to append.
+   */
+  virtual nsresult GetContainerData(nsTArray<nsTArray<uint8_t> >* aOutputBufs,
+                                    uint32_t aFlags = 0) = 0;
+
+protected:
+  bool mInitialized;
+};
+}
+#endif
new file mode 100644
--- /dev/null
+++ b/content/media/encoder/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+MODULE = 'content'
+
+EXPORTS += [
+    'ContainerWriter.h',
+]
--- a/content/media/moz.build
+++ b/content/media/moz.build
@@ -1,14 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+PARALLEL_DIRS += ['encoder']
+
 PARALLEL_DIRS += ['webaudio']
 
 if CONFIG['MOZ_RAW']:
     PARALLEL_DIRS += ['raw']
 
 if CONFIG['MOZ_OGG']:
     PARALLEL_DIRS += ['ogg']