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 #ifndef MEDIA_BASE_DECODER_BUFFER_H_ | 5 #ifndef MEDIA_BASE_DECODER_BUFFER_H_ |
6 #define MEDIA_BASE_DECODER_BUFFER_H_ | 6 #define MEDIA_BASE_DECODER_BUFFER_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/time.h" | 13 #include "base/time.h" |
12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
13 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
14 | 16 |
15 namespace media { | 17 namespace media { |
16 | 18 |
17 class DecryptConfig; | 19 class DecryptConfig; |
18 | 20 |
19 // A specialized buffer for interfacing with audio / video decoders. | 21 // A specialized buffer for interfacing with audio / video decoders. |
20 // | 22 // |
21 // Specifically ensures that data is aligned and padded as necessary by the | 23 // Specifically ensures that data is aligned and padded as necessary by the |
22 // underlying decoding framework. On desktop platforms this means memory is | 24 // underlying decoding framework. On desktop platforms this means memory is |
23 // allocated using FFmpeg with particular alignment and padding requirements. | 25 // allocated using FFmpeg with particular alignment and padding requirements. |
24 // | 26 // |
25 // Also includes decoder specific functionality for decryption. | 27 // Also includes decoder specific functionality for decryption. |
| 28 // |
| 29 // NOTE: It is illegal to call any method when IsEndOfStream() is true. |
26 class MEDIA_EXPORT DecoderBuffer | 30 class MEDIA_EXPORT DecoderBuffer |
27 : public base::RefCountedThreadSafe<DecoderBuffer> { | 31 : public base::RefCountedThreadSafe<DecoderBuffer> { |
28 public: | 32 public: |
29 enum { | 33 enum { |
30 kPaddingSize = 16, | 34 kPaddingSize = 16, |
31 #if defined(ARCH_CPU_ARM_FAMILY) | 35 #if defined(ARCH_CPU_ARM_FAMILY) |
32 kAlignmentSize = 16 | 36 kAlignmentSize = 16 |
33 #else | 37 #else |
34 kAlignmentSize = 32 | 38 kAlignmentSize = 32 |
35 #endif | 39 #endif |
36 }; | 40 }; |
37 | 41 |
38 // Allocates buffer with |size| >= 0. Buffer will be padded and aligned | 42 // Allocates buffer with |size| >= 0. Buffer will be padded and aligned |
39 // as necessary. | 43 // as necessary. |
40 explicit DecoderBuffer(int size); | 44 explicit DecoderBuffer(int size); |
41 | 45 |
42 // Create a DecoderBuffer whose |data_| is copied from |data|. Buffer will be | 46 // Create a DecoderBuffer whose |data_| is copied from |data|. Buffer will be |
43 // padded and aligned as necessary. |data| must not be NULL and |size| >= 0. | 47 // padded and aligned as necessary. |data| must not be NULL and |size| >= 0. |
44 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size); | 48 static scoped_refptr<DecoderBuffer> CopyFrom(const uint8* data, int size); |
45 | 49 |
46 // Create a DecoderBuffer indicating we've reached end of stream. GetData() | 50 // Create a DecoderBuffer indicating we've reached end of stream. |
47 // and GetWritableData() will return NULL and GetDataSize() will return 0. | 51 // |
| 52 // Calling any method other than IsEndOfStream() on the resulting buffer |
| 53 // is disallowed. |
48 static scoped_refptr<DecoderBuffer> CreateEOSBuffer(); | 54 static scoped_refptr<DecoderBuffer> CreateEOSBuffer(); |
49 | 55 |
50 base::TimeDelta GetTimestamp() const; | 56 base::TimeDelta GetTimestamp() const; |
51 void SetTimestamp(const base::TimeDelta& timestamp); | 57 void SetTimestamp(const base::TimeDelta& timestamp); |
52 | 58 |
53 base::TimeDelta GetDuration() const; | 59 base::TimeDelta GetDuration() const; |
54 void SetDuration(const base::TimeDelta& duration); | 60 void SetDuration(const base::TimeDelta& duration); |
55 | 61 |
56 const uint8* GetData() const; | 62 const uint8* GetData() const; |
57 uint8* GetWritableData() const; | 63 uint8* GetWritableData() const; |
58 | 64 |
59 int GetDataSize() const; | 65 int GetDataSize() const; |
60 | 66 |
61 const DecryptConfig* GetDecryptConfig() const; | 67 const DecryptConfig* GetDecryptConfig() const; |
62 void SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config); | 68 void SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config); |
63 | 69 |
64 // If there's no data in this buffer, it represents end of stream. | 70 // If there's no data in this buffer, it represents end of stream. |
65 bool IsEndOfStream() const; | 71 bool IsEndOfStream() const; |
66 | 72 |
| 73 // Returns a human-readable string describing |*this|. |
| 74 std::string AsHumanReadableString(); |
| 75 |
67 protected: | 76 protected: |
68 friend class base::RefCountedThreadSafe<DecoderBuffer>; | 77 friend class base::RefCountedThreadSafe<DecoderBuffer>; |
69 | 78 |
70 // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer | 79 // Allocates a buffer of size |size| >= 0 and copies |data| into it. Buffer |
71 // will be padded and aligned as necessary. If |data| is NULL then |data_| is | 80 // will be padded and aligned as necessary. If |data| is NULL then |data_| is |
72 // set to NULL and |buffer_size_| to 0. | 81 // set to NULL and |buffer_size_| to 0. |
73 DecoderBuffer(const uint8* data, int size); | 82 DecoderBuffer(const uint8* data, int size); |
74 virtual ~DecoderBuffer(); | 83 virtual ~DecoderBuffer(); |
75 | 84 |
76 private: | 85 private: |
77 base::TimeDelta timestamp_; | 86 base::TimeDelta timestamp_; |
78 base::TimeDelta duration_; | 87 base::TimeDelta duration_; |
79 | 88 |
80 int size_; | 89 int size_; |
81 scoped_ptr<uint8, base::ScopedPtrAlignedFree> data_; | 90 scoped_ptr<uint8, base::ScopedPtrAlignedFree> data_; |
82 scoped_ptr<DecryptConfig> decrypt_config_; | 91 scoped_ptr<DecryptConfig> decrypt_config_; |
83 | 92 |
84 // Constructor helper method for memory allocations. | 93 // Constructor helper method for memory allocations. |
85 void Initialize(); | 94 void Initialize(); |
86 | 95 |
87 DISALLOW_COPY_AND_ASSIGN(DecoderBuffer); | 96 DISALLOW_COPY_AND_ASSIGN(DecoderBuffer); |
88 }; | 97 }; |
89 | 98 |
90 } // namespace media | 99 } // namespace media |
91 | 100 |
92 #endif // MEDIA_BASE_DECODER_BUFFER_H_ | 101 #endif // MEDIA_BASE_DECODER_BUFFER_H_ |
OLD | NEW |