OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/base/decoder_buffer.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "media/base/decrypt_config.h" | |
9 #if !defined(OS_ANDROID) | |
10 #include "media/ffmpeg/ffmpeg_common.h" | |
11 #endif | |
12 | |
13 namespace media { | |
14 | |
15 DecoderBuffer::DecoderBuffer(int buffer_size) | |
16 : Buffer(base::TimeDelta(), base::TimeDelta()), | |
17 buffer_size_(buffer_size) { | |
18 DCHECK(buffer_size >= 0); | |
19 Initialize(); | |
20 } | |
21 | |
22 DecoderBuffer::DecoderBuffer(const uint8* data, int buffer_size) | |
23 : Buffer(base::TimeDelta(), base::TimeDelta()), | |
24 buffer_size_(data == NULL ? -1 : buffer_size) { | |
Ami GONE FROM CHROMIUM
2012/05/30 05:19:27
What's up with this -1?
(and why isn't it sending
DaleCurtis
2012/05/30 17:33:47
Ensures if a NULL buffer is passed in with 0 size
| |
25 Initialize(); | |
26 memcpy(data_, data, buffer_size_); | |
27 } | |
28 | |
29 DecoderBuffer::~DecoderBuffer() { | |
30 #if !defined(OS_ANDROID) | |
31 av_free(data_); | |
32 #else | |
33 delete[] data_; | |
34 #endif | |
35 } | |
36 | |
37 void DecoderBuffer::Initialize() { | |
38 // Prevent invalid allocations. Also used to create End Of Stream buffers. | |
39 if (buffer_size_ < 0) { | |
40 buffer_size_ = 0; | |
41 data_ = NULL; | |
42 return; | |
43 } | |
44 | |
45 #if !defined(OS_ANDROID) | |
46 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | |
47 // padded. Using av_malloc with padding ensures FFmpeg only recieves data | |
48 // padded and aligned to its specifications. | |
49 data_ = reinterpret_cast<uint8*>( | |
50 av_malloc(buffer_size_ + FF_INPUT_BUFFER_PADDING_SIZE)); | |
51 memset(data_ + buffer_size_, 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
52 #else | |
53 data_ = new uint8[buffer_size_]; | |
54 #endif | |
55 } | |
56 | |
57 scoped_refptr<DecoderBuffer> DecoderBuffer::CopyFrom(const uint8* data, | |
58 int data_size) { | |
59 DCHECK(data && data_size >= 0); | |
60 return make_scoped_refptr(new DecoderBuffer(data, data_size)); | |
61 } | |
62 | |
63 scoped_refptr<DecoderBuffer> DecoderBuffer::CreateEOSBuffer() { | |
64 return make_scoped_refptr(new DecoderBuffer(NULL, -1)); | |
Ami GONE FROM CHROMIUM
2012/05/30 05:19:27
Again, I think -1 is just asking for trouble. Why
DaleCurtis
2012/05/30 17:33:47
Done.
| |
65 } | |
66 | |
67 const uint8* DecoderBuffer::GetData() const { | |
68 return data_; | |
69 } | |
70 | |
71 int DecoderBuffer::GetDataSize() const { | |
72 return buffer_size_; | |
73 } | |
74 | |
75 uint8* DecoderBuffer::GetWritableData() { | |
76 return data_; | |
77 } | |
78 | |
79 const DecryptConfig* DecoderBuffer::GetDecryptConfig() const { | |
80 return decrypt_config_.get(); | |
81 } | |
82 | |
83 void DecoderBuffer::SetDecryptConfig(scoped_ptr<DecryptConfig> decrypt_config) { | |
84 decrypt_config_ = decrypt_config.Pass(); | |
85 } | |
86 | |
87 } // namespace media | |
OLD | NEW |