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

Side by Side Diff: media/base/video_frame_impl.cc

Issue 113611: Handle end of stream for media... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/base/video_frame_impl.h" 5 #include "media/base/video_frame_impl.h"
6 6
7 namespace media { 7 namespace media {
8 8
9 // static 9 // static
10 void VideoFrameImpl::CreateFrame(VideoSurface::Format format, 10 void VideoFrameImpl::CreateFrame(VideoSurface::Format format,
(...skipping 29 matching lines...) Expand all
40 break; 40 break;
41 default: 41 default:
42 NOTREACHED(); 42 NOTREACHED();
43 alloc_worked = false; 43 alloc_worked = false;
44 break; 44 break;
45 } 45 }
46 } 46 }
47 *frame_out = alloc_worked ? frame : NULL; 47 *frame_out = alloc_worked ? frame : NULL;
48 } 48 }
49 49
50 // static
51 void VideoFrameImpl::CreateEmptyFrame(scoped_refptr<VideoFrame>* frame_out) {
52 *frame_out = new VideoFrameImpl(VideoSurface::EMPTY, 0, 0);
53 }
54
50 static inline size_t RoundUp(size_t value, size_t alignment) { 55 static inline size_t RoundUp(size_t value, size_t alignment) {
51 // Check that |alignment| is a power of 2. 56 // Check that |alignment| is a power of 2.
52 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1))); 57 DCHECK((alignment + (alignment - 1)) == (alignment | (alignment - 1)));
53 return ((value + (alignment - 1)) & ~(alignment-1)); 58 return ((value + (alignment - 1)) & ~(alignment-1));
54 } 59 }
55 60
56 bool VideoFrameImpl::AllocateRGB(size_t bytes_per_pixel) { 61 bool VideoFrameImpl::AllocateRGB(size_t bytes_per_pixel) {
57 // Round up to align at a 64-bit (8 byte) boundary for each row. This 62 // Round up to align at a 64-bit (8 byte) boundary for each row. This
58 // is sufficient for MMX reads (movq). 63 // is sufficient for MMX reads (movq).
59 size_t bytes_per_row = RoundUp(surface_.width * bytes_per_pixel, 8); 64 size_t bytes_per_row = RoundUp(surface_.width * bytes_per_pixel, 8);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 120
116 VideoFrameImpl::~VideoFrameImpl() { 121 VideoFrameImpl::~VideoFrameImpl() {
117 // In multi-plane allocations, only a single block of memory is allocated 122 // In multi-plane allocations, only a single block of memory is allocated
118 // on the heap, and other |data| pointers point inside the same, single block 123 // on the heap, and other |data| pointers point inside the same, single block
119 // so just delete index 0. 124 // so just delete index 0.
120 delete[] surface_.data[0]; 125 delete[] surface_.data[0];
121 } 126 }
122 127
123 bool VideoFrameImpl::Lock(VideoSurface* surface) { 128 bool VideoFrameImpl::Lock(VideoSurface* surface) {
124 DCHECK(!locked_); 129 DCHECK(!locked_);
130 DCHECK_NE(surface_.format, VideoSurface::EMPTY);
125 if (locked_) { 131 if (locked_) {
126 memset(surface, 0, sizeof(*surface)); 132 memset(surface, 0, sizeof(*surface));
127 return false; 133 return false;
128 } 134 }
129 locked_ = true; 135 locked_ = true;
130 COMPILE_ASSERT(sizeof(*surface) == sizeof(surface_), surface_size_mismatch); 136 COMPILE_ASSERT(sizeof(*surface) == sizeof(surface_), surface_size_mismatch);
131 memcpy(surface, &surface_, sizeof(*surface)); 137 memcpy(surface, &surface_, sizeof(*surface));
132 return true; 138 return true;
133 } 139 }
134 140
135 void VideoFrameImpl::Unlock() { 141 void VideoFrameImpl::Unlock() {
136 DCHECK(locked_); 142 DCHECK(locked_);
143 DCHECK_NE(surface_.format, VideoSurface::EMPTY);
137 locked_ = false; 144 locked_ = false;
138 } 145 }
139 146
147 bool VideoFrameImpl::IsEndOfStream() const {
148 return surface_.format == VideoSurface::EMPTY;
149 }
150
140 } // namespace media 151 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698