| OLD | NEW |
| 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/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <climits> | 8 #include <climits> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/aligned_memory.h" | 15 #include "base/memory/aligned_memory.h" |
| 16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| 20 #include "media/base/timestamp_constants.h" | 20 #include "media/base/timestamp_constants.h" |
| 21 #include "media/base/video_util.h" | 21 #include "media/base/video_util.h" |
| 22 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 namespace { |
| 27 |
| 28 // Helper to privide gfx::Rect::Intersect() as an expression. |
| 29 gfx::Rect Intersection(gfx::Rect a, const gfx::Rect& b) { |
| 30 a.Intersect(b); |
| 31 return a; |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 26 // Static POD class for generating unique identifiers for each VideoFrame. | 36 // Static POD class for generating unique identifiers for each VideoFrame. |
| 27 static base::StaticAtomicSequenceNumber g_unique_id_generator; | 37 static base::StaticAtomicSequenceNumber g_unique_id_generator; |
| 28 | 38 |
| 29 static bool IsPowerOfTwo(size_t x) { | 39 static bool IsPowerOfTwo(size_t x) { |
| 30 return x != 0 && (x & (x - 1)) == 0; | 40 return x != 0 && (x & (x - 1)) == 0; |
| 31 } | 41 } |
| 32 | 42 |
| 33 static inline size_t RoundUp(size_t value, size_t alignment) { | 43 static inline size_t RoundUp(size_t value, size_t alignment) { |
| 34 DCHECK(IsPowerOfTwo(alignment)); | 44 DCHECK(IsPowerOfTwo(alignment)); |
| 35 return ((value + (alignment - 1)) & ~(alignment - 1)); | 45 return ((value + (alignment - 1)) & ~(alignment - 1)); |
| (...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 | 926 |
| 917 VideoFrame::VideoFrame(VideoPixelFormat format, | 927 VideoFrame::VideoFrame(VideoPixelFormat format, |
| 918 StorageType storage_type, | 928 StorageType storage_type, |
| 919 const gfx::Size& coded_size, | 929 const gfx::Size& coded_size, |
| 920 const gfx::Rect& visible_rect, | 930 const gfx::Rect& visible_rect, |
| 921 const gfx::Size& natural_size, | 931 const gfx::Size& natural_size, |
| 922 base::TimeDelta timestamp) | 932 base::TimeDelta timestamp) |
| 923 : format_(format), | 933 : format_(format), |
| 924 storage_type_(storage_type), | 934 storage_type_(storage_type), |
| 925 coded_size_(coded_size), | 935 coded_size_(coded_size), |
| 926 visible_rect_(visible_rect), | 936 visible_rect_(Intersection(visible_rect, gfx::Rect(coded_size))), |
| 927 natural_size_(natural_size), | 937 natural_size_(natural_size), |
| 928 shared_memory_offset_(0), | 938 shared_memory_offset_(0), |
| 929 timestamp_(timestamp), | 939 timestamp_(timestamp), |
| 930 unique_id_(g_unique_id_generator.GetNext()) { | 940 unique_id_(g_unique_id_generator.GetNext()) { |
| 931 DCHECK(IsValidConfig(format_, storage_type, coded_size_, visible_rect_, | 941 DCHECK(IsValidConfig(format_, storage_type, coded_size_, visible_rect_, |
| 932 natural_size_)); | 942 natural_size_)); |
| 943 DCHECK(visible_rect_ == visible_rect) |
| 944 << "visible_rect " << visible_rect.ToString() << " exceeds coded_size " |
| 945 << coded_size.ToString(); |
| 933 memset(&mailbox_holders_, 0, sizeof(mailbox_holders_)); | 946 memset(&mailbox_holders_, 0, sizeof(mailbox_holders_)); |
| 934 memset(&strides_, 0, sizeof(strides_)); | 947 memset(&strides_, 0, sizeof(strides_)); |
| 935 memset(&data_, 0, sizeof(data_)); | 948 memset(&data_, 0, sizeof(data_)); |
| 936 } | 949 } |
| 937 | 950 |
| 938 VideoFrame::~VideoFrame() { | 951 VideoFrame::~VideoFrame() { |
| 939 if (!mailbox_holders_release_cb_.is_null()) { | 952 if (!mailbox_holders_release_cb_.is_null()) { |
| 940 gpu::SyncToken release_sync_token; | 953 gpu::SyncToken release_sync_token; |
| 941 { | 954 { |
| 942 // To ensure that changes to |release_sync_token_| are visible on this | 955 // To ensure that changes to |release_sync_token_| are visible on this |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 if (zero_initialize_memory) | 1218 if (zero_initialize_memory) |
| 1206 memset(data, 0, data_size); | 1219 memset(data, 0, data_size); |
| 1207 | 1220 |
| 1208 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) | 1221 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) |
| 1209 data_[plane] = data + offset[plane]; | 1222 data_[plane] = data + offset[plane]; |
| 1210 | 1223 |
| 1211 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); | 1224 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); |
| 1212 } | 1225 } |
| 1213 | 1226 |
| 1214 } // namespace media | 1227 } // namespace media |
| OLD | NEW |