Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_ | |
| 6 #define MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_ | |
| 7 | |
| 8 #include <stack> | |
| 9 #include <stdio.h> | |
| 10 | |
| 11 #include "base/file_path.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "media/base/media_export.h" | |
| 14 #include "media/webm/chromeos/ebml_writer.h" | |
| 15 | |
| 16 extern "C" { | |
| 17 #define VPX_CODEC_DISABLE_COMPAT 1 | |
| 18 #include "third_party/libvpx/libvpx.h" | |
| 19 } | |
| 20 | |
| 21 class FilePath; | |
| 22 class SkBitmap; | |
| 23 | |
| 24 namespace media { | |
| 25 | |
| 26 namespace chromeos { | |
| 27 | |
| 28 // WebM encoder using libvpx. Currently only supports one-pass, constant bitrate | |
| 29 // encoding of short files consisting of a single video track. Seek info and | |
| 30 // cues are not supported, so generated .webm file does not strictly adhere to | |
| 31 // WebM standard (http://www.webmproject.org/code/specs/container/). | |
| 32 class MEDIA_EXPORT WebmEncoder { | |
| 33 public: | |
| 34 // Create new instance for writing to |output_path|. If |realtime| is |true|, | |
| 35 // uses realtime deadline, otherwise - "good quality" deadline. | |
| 36 WebmEncoder(const FilePath& output_path, unsigned bitrate, bool realtime); | |
|
scherkus (not reviewing)
2012/07/19 21:46:03
you can use int for bitrate -- we do elsewhere in
Ivan Korotkov
2012/07/20 11:10:36
Done.
| |
| 37 | |
| 38 // Encodes video from a Nx(N*M) sprite, having M frames of size NxN with FPS | |
| 39 // |fps_n/fps_d|. Must be called on a thread that allows IO. | |
| 40 void EncodeFromSprite(const SkBitmap& sprite, int fps_n, int fps_d); | |
| 41 | |
| 42 private: | |
| 43 // Write global WebM header and starts a single video track. | |
| 44 void WriteWebmHeader(); | |
| 45 // Writes VPX packet to output file. | |
| 46 void WriteWebmBlock(const vpx_codec_cx_pkt_t* packet); | |
| 47 // Finished video track and closes output file. | |
| 48 void WriteWebmFooter(); | |
| 49 | |
| 50 // Starts a new WebM sub-element of given type. Those can be nested. | |
| 51 void StartSubElement(unsigned long class_id); | |
| 52 // Closes current top-level sub-element. | |
| 53 void EndSubElement(); | |
| 54 | |
| 55 // libmkv callbacks. | |
| 56 void EbmlWrite(const void* buffer, unsigned long len); | |
| 57 void EbmlSerialize(const void* buffer, int buffer_size, unsigned long len); | |
| 58 | |
| 59 template <typename T> | |
| 60 void EbmlSerializeHelper(const T* buffer, unsigned long len); | |
| 61 | |
| 62 // Video dimensions and FPS. | |
| 63 size_t width_; | |
| 64 size_t height_; | |
| 65 vpx_rational_t fps_; | |
| 66 | |
| 67 // Single I420 frame data. | |
| 68 scoped_array<uint8> yuv_frame_; | |
| 69 | |
| 70 // VPX config in use. | |
| 71 vpx_codec_enc_cfg_t config_; | |
| 72 | |
| 73 // VPX parameters. | |
| 74 unsigned bitrate_; | |
| 75 unsigned long deadline_; | |
| 76 | |
| 77 // EbmlWriter context. | |
| 78 EbmlGlobal ebml_writer_; | |
| 79 | |
| 80 // Stack with start offsets of currently open sub-elements. | |
| 81 std::stack<long int> ebml_sub_elements_; | |
| 82 | |
| 83 FilePath output_path_; | |
| 84 FILE* output_; | |
| 85 }; | |
|
scherkus (not reviewing)
2012/07/19 21:46:03
DISALLOW etc...
Ivan Korotkov
2012/07/20 11:10:36
Done.
| |
| 86 | |
| 87 } // namespace chromeos | |
| 88 | |
| 89 } // namespace media | |
| 90 | |
| 91 #endif // MEDIA_WEBM_CHROMEOS_WEBM_ENCODER_H_ | |
| OLD | NEW |