Index: chrome/browser/chromeos/webm_encoder.h |
diff --git a/chrome/browser/chromeos/webm_encoder.h b/chrome/browser/chromeos/webm_encoder.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..097854c0625a6ade775c1da92db604692d30aa53 |
--- /dev/null |
+++ b/chrome/browser/chromeos/webm_encoder.h |
@@ -0,0 +1,86 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_WEBM_ENCODER_H_ |
+#define CHROME_BROWSER_CHROMEOS_WEBM_ENCODER_H_ |
+ |
+#include <stack> |
+#include <stdio.h> |
+ |
+#include "base/file_path.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "chrome/browser/chromeos/ebml_writer.h" |
+ |
+extern "C" { |
+#define VPX_CODEC_DISABLE_COMPAT 1 |
+#include "third_party/libvpx/libvpx.h" |
+} |
+ |
+class FilePath; |
+class SkBitmap; |
+ |
+namespace chromeos { |
+ |
+// WebM encoder using libvpx. Currently only supports one-pass, constant bitrate |
+// encoding of short files consisting of a single video track. Seek info and |
+// cues are not supported, so generated .webm file does not strictly adhere to |
+// WebM standard (http://www.webmproject.org/code/specs/container/). |
+class WebmEncoder { |
+ public: |
+ // Create new instance for writing to |output_path|. If |realtime| is |true|, |
+ // uses realtime deadline, otherwise - "good quality" deadline. |
+ WebmEncoder(const FilePath& output_path, unsigned bitrate, bool realtime); |
+ |
+ // Encodes video from a Nx(N*M) sprite, having M frames of size NxN with FPS |
+ // |fps_n/fps_d|. Must be called on a thread that allows IO. |
Nikita (slow)
2012/07/18 16:23:05
nit: allows disk IO
Ivan Korotkov
2012/07/20 09:09:29
Done.
|
+ void EncodeFromSprite(const SkBitmap& sprite, int fps_n, int fps_d); |
+ |
+ private: |
+ // Write global WebM header and starts a single video track. |
Nikita (slow)
2012/07/18 16:23:05
nit: Writes
Ivan Korotkov
2012/07/20 09:09:29
Done.
|
+ void WriteWebmHeader(); |
+ // Writes VPX packet to output file. |
Nikita (slow)
2012/07/18 16:23:05
nit: insert empty line
Ivan Korotkov
2012/07/20 09:09:29
Done.
|
+ void WriteWebmBlock(const vpx_codec_cx_pkt_t* packet); |
+ // Finished video track and closes output file. |
Nikita (slow)
2012/07/18 16:23:05
nit: insert empty line
nit: Finishes
Ivan Korotkov
2012/07/20 09:09:29
Done.
|
+ void WriteWebmFooter(); |
+ |
+ // Starts a new WebM sub-element of given type. Those can be nested. |
+ void StartSubElement(unsigned long class_id); |
+ // Closes current top-level sub-element. |
Nikita (slow)
2012/07/18 16:23:05
nit: insert empty line
Ivan Korotkov
2012/07/20 09:09:29
Done.
|
+ void EndSubElement(); |
+ |
+ // libmkv callbacks. |
+ void EbmlWrite(const void* buffer, unsigned long len); |
+ void EbmlSerialize(const void* buffer, int buffer_size, unsigned long len); |
+ |
+ template <typename T> |
+ void EbmlSerializeHelper(const T* buffer, unsigned long len); |
+ |
+ // Video dimensions and FPS. |
+ size_t width_; |
+ size_t height_; |
+ vpx_rational_t fps_; |
+ |
+ // Single I420 frame data. |
+ scoped_array<uint8> yuv_frame_; |
+ |
+ // VPX config in use. |
+ vpx_codec_enc_cfg_t config_; |
+ |
+ // VPX parameters. |
+ unsigned bitrate_; |
+ unsigned long deadline_; |
+ |
+ // EbmlWriter context. |
+ EbmlGlobal ebml_writer_; |
+ |
+ // Stack with start offsets of currently open sub-elements. |
+ std::stack<long int> ebml_sub_elements_; |
+ |
+ FilePath output_path_; |
+ FILE* output_; |
+}; |
+ |
+} // namespace chromeos |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_WEBM_ENCODER_H_ |