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_MOCK_READER_H_ | 5 #ifndef MEDIA_BASE_MOCK_READER_H_ |
6 #define MEDIA_BASE_MOCK_READER_H_ | 6 #define MEDIA_BASE_MOCK_READER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "media/base/filters.h" | 12 #include "media/base/filters.h" |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 // Ref counted object so we can create callbacks for asynchronous Read() | 16 // Ref counted object so we can create callbacks for asynchronous Read() |
17 // methods for any filter type. | 17 // methods for any filter type. |
18 template <class FilterType, class BufferType> | 18 class DemuxerStreamReader |
Ami GONE FROM CHROMIUM
2012/06/26 00:33:21
rename file?
acolwell GONE FROM CHROMIUM
2012/07/12 01:19:38
Removed file in a separate CL.
| |
19 class MockReader | 19 : public base::RefCountedThreadSafe<DemuxerStreamReader> { |
20 : public base::RefCountedThreadSafe<MockReader<FilterType, BufferType> > { | |
21 public: | 20 public: |
22 MockReader() | 21 DemuxerStreamReader() |
23 : called_(false), | 22 : called_(false), |
24 expecting_call_(false) { | 23 expecting_call_(false) { |
25 } | 24 } |
26 | 25 |
27 virtual ~MockReader() { | 26 virtual ~DemuxerStreamReader() { |
28 } | 27 } |
29 | 28 |
30 // Prepares this object for another read. | 29 // Prepares this object for another read. |
31 void Reset() { | 30 void Reset() { |
32 DCHECK(!expecting_call_); | 31 DCHECK(!expecting_call_); |
33 expecting_call_ = false; | 32 expecting_call_ = false; |
34 called_ = false; | 33 called_ = false; |
34 status_ = DemuxerStream::kAborted; | |
35 buffer_ = NULL; | 35 buffer_ = NULL; |
36 } | 36 } |
37 | 37 |
38 // Executes an asynchronous read on the given filter. | 38 // Executes an asynchronous read on the DemuxerStream. |
39 void Read(FilterType* filter) { | 39 void Read(DemuxerStream* filter) { |
40 DCHECK(!expecting_call_); | 40 DCHECK(!expecting_call_); |
41 called_ = false; | 41 called_ = false; |
42 expecting_call_ = true; | 42 expecting_call_ = true; |
43 filter->Read(base::Bind(&MockReader::OnReadComplete, this)); | 43 filter->Read(base::Bind(&DemuxerStreamReader::OnReadComplete, this)); |
44 } | 44 } |
45 | 45 |
46 // Mock accessors. | 46 // Mock accessors. |
47 BufferType* buffer() { return buffer_; } | 47 DecoderBuffer* buffer() { return buffer_; } |
48 bool called() { return called_; } | 48 bool called() { return called_; } |
49 bool expecting_call() { return expecting_call_; } | 49 bool expecting_call() { return expecting_call_; } |
50 | 50 |
51 private: | 51 private: |
52 void OnReadComplete(const scoped_refptr<BufferType>& buffer) { | 52 void OnReadComplete(DemuxerStream::Status status, |
53 const scoped_refptr<DecoderBuffer>& buffer) { | |
53 DCHECK(!called_); | 54 DCHECK(!called_); |
54 DCHECK(expecting_call_); | 55 DCHECK(expecting_call_); |
55 expecting_call_ = false; | 56 expecting_call_ = false; |
56 called_ = true; | 57 called_ = true; |
58 status_ = status; | |
57 buffer_ = buffer; | 59 buffer_ = buffer; |
58 } | 60 } |
59 | 61 |
62 DemuxerStream::Status status_; | |
63 | |
60 // Reference to the buffer provided in the callback. | 64 // Reference to the buffer provided in the callback. |
61 scoped_refptr<BufferType> buffer_; | 65 scoped_refptr<DecoderBuffer> buffer_; |
62 | 66 |
63 // Whether or not the callback was executed. | 67 // Whether or not the callback was executed. |
64 bool called_; | 68 bool called_; |
65 | 69 |
66 // Whether or not this reader was expecting a callback. | 70 // Whether or not this reader was expecting a callback. |
67 bool expecting_call_; | 71 bool expecting_call_; |
68 | 72 |
69 DISALLOW_COPY_AND_ASSIGN(MockReader); | 73 DISALLOW_COPY_AND_ASSIGN(DemuxerStreamReader); |
70 }; | 74 }; |
71 | 75 |
72 // Commonly used reader types. | |
73 typedef MockReader<DemuxerStream, DecoderBuffer> DemuxerStreamReader; | |
74 | |
75 } // namespace media | 76 } // namespace media |
76 | 77 |
77 #endif // MEDIA_BASE_MOCK_READER_H_ | 78 #endif // MEDIA_BASE_MOCK_READER_H_ |
OLD | NEW |