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/bind.h" | 11 #include "base/bind.h" |
11 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/aligned_memory.h" | 15 #include "base/memory/aligned_memory.h" |
15 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
19 #include "media/base/timestamp_constants.h" | 20 #include "media/base/timestamp_constants.h" |
20 #include "media/base/video_util.h" | 21 #include "media/base/video_util.h" |
21 #include "ui/gfx/geometry/point.h" | 22 #include "ui/gfx/geometry/point.h" |
22 | 23 |
23 namespace media { | 24 namespace media { |
24 | 25 |
| 26 // Static POD class for generating unique identifiers for each VideoFrame. |
| 27 static base::StaticAtomicSequenceNumber g_unique_id_generator; |
| 28 |
25 static bool IsPowerOfTwo(size_t x) { | 29 static bool IsPowerOfTwo(size_t x) { |
26 return x != 0 && (x & (x - 1)) == 0; | 30 return x != 0 && (x & (x - 1)) == 0; |
27 } | 31 } |
28 | 32 |
29 static inline size_t RoundUp(size_t value, size_t alignment) { | 33 static inline size_t RoundUp(size_t value, size_t alignment) { |
30 DCHECK(IsPowerOfTwo(alignment)); | 34 DCHECK(IsPowerOfTwo(alignment)); |
31 return ((value + (alignment - 1)) & ~(alignment - 1)); | 35 return ((value + (alignment - 1)) & ~(alignment - 1)); |
32 } | 36 } |
33 | 37 |
34 static inline size_t RoundDown(size_t value, size_t alignment) { | 38 static inline size_t RoundDown(size_t value, size_t alignment) { |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 const gfx::Rect& visible_rect, | 842 const gfx::Rect& visible_rect, |
839 const gfx::Size& natural_size, | 843 const gfx::Size& natural_size, |
840 base::TimeDelta timestamp) | 844 base::TimeDelta timestamp) |
841 : format_(format), | 845 : format_(format), |
842 storage_type_(storage_type), | 846 storage_type_(storage_type), |
843 coded_size_(coded_size), | 847 coded_size_(coded_size), |
844 visible_rect_(visible_rect), | 848 visible_rect_(visible_rect), |
845 natural_size_(natural_size), | 849 natural_size_(natural_size), |
846 shared_memory_handle_(base::SharedMemory::NULLHandle()), | 850 shared_memory_handle_(base::SharedMemory::NULLHandle()), |
847 shared_memory_offset_(0), | 851 shared_memory_offset_(0), |
848 timestamp_(timestamp) { | 852 timestamp_(timestamp), |
| 853 unique_id_(g_unique_id_generator.GetNext()) { |
849 DCHECK(IsValidConfig(format_, storage_type, coded_size_, visible_rect_, | 854 DCHECK(IsValidConfig(format_, storage_type, coded_size_, visible_rect_, |
850 natural_size_)); | 855 natural_size_)); |
851 memset(&mailbox_holders_, 0, sizeof(mailbox_holders_)); | 856 memset(&mailbox_holders_, 0, sizeof(mailbox_holders_)); |
852 memset(&strides_, 0, sizeof(strides_)); | 857 memset(&strides_, 0, sizeof(strides_)); |
853 memset(&data_, 0, sizeof(data_)); | 858 memset(&data_, 0, sizeof(data_)); |
854 } | 859 } |
855 | 860 |
856 VideoFrame::~VideoFrame() { | 861 VideoFrame::~VideoFrame() { |
857 if (!mailbox_holders_release_cb_.is_null()) { | 862 if (!mailbox_holders_release_cb_.is_null()) { |
858 gpu::SyncToken release_sync_token; | 863 gpu::SyncToken release_sync_token; |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 if (zero_initialize_memory) | 1116 if (zero_initialize_memory) |
1112 memset(data, 0, data_size); | 1117 memset(data, 0, data_size); |
1113 | 1118 |
1114 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) | 1119 for (size_t plane = 0; plane < NumPlanes(format_); ++plane) |
1115 data_[plane] = data + offset[plane]; | 1120 data_[plane] = data + offset[plane]; |
1116 | 1121 |
1117 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); | 1122 AddDestructionObserver(base::Bind(&base::AlignedFree, data)); |
1118 } | 1123 } |
1119 | 1124 |
1120 } // namespace media | 1125 } // namespace media |
OLD | NEW |