Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: media/webm/chromeos/webm_encoder.cc

Issue 10823006: Add proper duration to WebmEncoder-created files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/webm/chromeos/webm_encoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/webm/chromeos/webm_encoder.h" 5 #include "media/webm/chromeos/webm_encoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_generic_obj.h" 10 #include "base/memory/scoped_generic_obj.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 DCHECK(!sprite.isNull()); 77 DCHECK(!sprite.isNull());
78 DCHECK(!sprite.empty()); 78 DCHECK(!sprite.empty());
79 79
80 has_errors_ = false; 80 has_errors_ = false;
81 width_ = sprite.width(); 81 width_ = sprite.width();
82 height_ = sprite.width(); 82 height_ = sprite.width();
83 fps_.num = fps_n; 83 fps_.num = fps_n;
84 fps_.den = fps_d; 84 fps_.den = fps_d;
85 85
86 // Sprite is tiled vertically. 86 // Sprite is tiled vertically.
87 size_t frame_count = sprite.height() / width_; 87 frame_count_ = sprite.height() / width_;
88 88
89 vpx_image_t image; 89 vpx_image_t image;
90 vpx_img_alloc(&image, VPX_IMG_FMT_I420, width_, height_, 16); 90 vpx_img_alloc(&image, VPX_IMG_FMT_I420, width_, height_, 16);
91 // Ensure that image is freed after return. 91 // Ensure that image is freed after return.
92 ScopedGenericObj<vpx_image_t*, VpxImgFreeHelper> image_ptr(&image); 92 ScopedGenericObj<vpx_image_t*, VpxImgFreeHelper> image_ptr(&image);
93 93
94 const vpx_codec_iface_t* codec_iface = vpx_codec_vp8_cx(); 94 const vpx_codec_iface_t* codec_iface = vpx_codec_vp8_cx();
95 DCHECK(codec_iface); 95 DCHECK(codec_iface);
96 vpx_codec_err_t ret = vpx_codec_enc_config_default(codec_iface, &config_, 0); 96 vpx_codec_err_t ret = vpx_codec_enc_config_default(codec_iface, &config_, 0);
97 DCHECK_EQ(VPX_CODEC_OK, ret); 97 DCHECK_EQ(VPX_CODEC_OK, ret);
(...skipping 19 matching lines...) Expand all
117 117
118 SkAutoLockPixels lock_sprite(sprite); 118 SkAutoLockPixels lock_sprite(sprite);
119 119
120 const uint8* src = reinterpret_cast<const uint8*>(sprite.getAddr32(0, 0)); 120 const uint8* src = reinterpret_cast<const uint8*>(sprite.getAddr32(0, 0));
121 size_t src_frame_size = sprite.getSize(); 121 size_t src_frame_size = sprite.getSize();
122 int crop_y = 0; 122 int crop_y = 0;
123 123
124 if (!WriteWebmHeader()) 124 if (!WriteWebmHeader())
125 return false; 125 return false;
126 126
127 for (size_t frame = 0; frame < frame_count && !has_errors_; ++frame) { 127 for (size_t frame = 0; frame < frame_count_ && !has_errors_; ++frame) {
128 int res = libyuv::ConvertToI420( 128 int res = libyuv::ConvertToI420(
129 src, src_frame_size, 129 src, src_frame_size,
130 image.planes[VPX_PLANE_Y], image.stride[VPX_PLANE_Y], 130 image.planes[VPX_PLANE_Y], image.stride[VPX_PLANE_Y],
131 image.planes[VPX_PLANE_U], image.stride[VPX_PLANE_U], 131 image.planes[VPX_PLANE_U], image.stride[VPX_PLANE_U],
132 image.planes[VPX_PLANE_V], image.stride[VPX_PLANE_V], 132 image.planes[VPX_PLANE_V], image.stride[VPX_PLANE_V],
133 0, crop_y, // src origin 133 0, crop_y, // src origin
134 width_, sprite.height(), // src size 134 width_, sprite.height(), // src size
135 width_, height_, // dest size 135 width_, height_, // dest size
136 libyuv::kRotate0, 136 libyuv::kRotate0,
137 libyuv::FOURCC_ARGB); 137 libyuv::FOURCC_ARGB);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 176 }
177 EndSubElement(); // EBML 177 EndSubElement(); // EBML
178 178
179 // Single segment with a video track. 179 // Single segment with a video track.
180 StartSubElement(Segment); 180 StartSubElement(Segment);
181 { 181 {
182 StartSubElement(Info); 182 StartSubElement(Info);
183 { 183 {
184 // All timecodes in the segment will be expressed in milliseconds. 184 // All timecodes in the segment will be expressed in milliseconds.
185 Ebml_SerializeUnsigned(&ebml_writer_, TimecodeScale, 1000000); 185 Ebml_SerializeUnsigned(&ebml_writer_, TimecodeScale, 1000000);
186 double duration = 1000. * frame_count_ * fps_.den / fps_.num;
187 Ebml_SerializeFloat(&ebml_writer_, Segment_Duration, duration);
186 } 188 }
187 EndSubElement(); // Info 189 EndSubElement(); // Info
188 190
189 StartSubElement(Tracks); 191 StartSubElement(Tracks);
190 { 192 {
191 StartSubElement(TrackEntry); 193 StartSubElement(TrackEntry);
192 { 194 {
193 Ebml_SerializeUnsigned(&ebml_writer_, TrackNumber, 1); 195 Ebml_SerializeUnsigned(&ebml_writer_, TrackNumber, 1);
194 Ebml_SerializeUnsigned32(&ebml_writer_, TrackUID, 1); 196 Ebml_SerializeUnsigned32(&ebml_writer_, TrackUID, 1);
195 Ebml_SerializeUnsigned(&ebml_writer_, TrackType, 1); // Video 197 Ebml_SerializeUnsigned(&ebml_writer_, TrackType, 1); // Video
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 case 8: 314 case 8:
313 return EbmlSerializeHelper(static_cast<const int64_t*>(buffer), len); 315 return EbmlSerializeHelper(static_cast<const int64_t*>(buffer), len);
314 default: 316 default:
315 NOTREACHED() << "Invalid EbmlSerialize length: " << len; 317 NOTREACHED() << "Invalid EbmlSerialize length: " << len;
316 } 318 }
317 } 319 }
318 320
319 } // namespace chromeos 321 } // namespace chromeos
320 322
321 } // namespace media 323 } // namespace media
OLDNEW
« no previous file with comments | « media/webm/chromeos/webm_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698