Chromium Code Reviews| 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 #ifndef MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ | |
| 6 #define MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/compiler_specific.h" | |
|
DaleCurtis
2012/11/13 03:42:28
Needed?
scherkus (not reviewing)
2012/11/13 18:19:13
Done.
| |
| 11 #include "base/synchronization/waitable_event.h" | |
| 12 #include "media/filters/ffmpeg_glue.h" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 class DataSource; | |
| 17 | |
| 18 // An implementation of FFmpegURLProtocol that blocks until the underlying | |
| 19 // asynchronous DataSource::Read() operation completes. | |
| 20 // | |
| 21 // TODO(scherkus): Should be more thread-safe and use ConditionVariable+Lock as | |
|
DaleCurtis
2012/11/13 03:42:28
WaitableEvent uses CV under the hood, so I think t
scherkus (not reviewing)
2012/11/13 18:19:13
WEs are implemented using OS primitives (e.g., HAN
DaleCurtis
2012/11/13 21:44:07
Whoops, I was looking at the internal posix SyncWa
| |
| 22 // opposed to a WaitableEvent. | |
| 23 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol { | |
| 24 public: | |
| 25 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is | |
| 26 // fired any time DataSource::Read() returns an error. | |
| 27 // | |
| 28 // TODO(scherkus): After all blocking operations are isolated on a separate | |
| 29 // thread we should be able to eliminate |error_cb|. | |
| 30 BlockingUrlProtocol(const scoped_refptr<DataSource>& data_source, | |
| 31 const base::Closure& error_cb); | |
| 32 virtual ~BlockingUrlProtocol(); | |
| 33 | |
| 34 // Aborts any pending reads by returning a read error. After this method | |
| 35 // returns all subsequent calls to Read() will immediately fail. | |
| 36 // | |
| 37 // TODO(scherkus): Currently this will cause |error_cb| to fire. Fix. | |
| 38 void Abort(); | |
| 39 | |
| 40 // FFmpegURLProtocol methods. | |
| 41 virtual int Read(int size, uint8* data) OVERRIDE; | |
| 42 virtual bool GetPosition(int64* position_out) OVERRIDE; | |
| 43 virtual bool SetPosition(int64 position) OVERRIDE; | |
| 44 virtual bool GetSize(int64* size_out) OVERRIDE; | |
| 45 virtual bool IsStreaming() OVERRIDE; | |
| 46 | |
| 47 private: | |
| 48 // Sets |last_read_bytes_| and signals the blocked thread that the read | |
| 49 // has completed. | |
| 50 void SignalReadCompleted(int size); | |
| 51 | |
| 52 scoped_refptr<DataSource> data_source_; | |
| 53 base::Closure error_cb_; | |
| 54 | |
| 55 // Used to convert an asynchronous DataSource::Read() into a blocking | |
| 56 // FFmpegUrlProtocol::Read(). | |
| 57 base::WaitableEvent read_event_; | |
| 58 | |
| 59 // Read errors and aborts are unrecoverable. Any subsequent reads will | |
| 60 // immediately fail when this is set to true. | |
| 61 bool read_has_failed_; | |
| 62 | |
| 63 // Cached number of bytes last read from the data source. | |
| 64 int last_read_bytes_; | |
| 65 | |
| 66 // Cached position within the data source. | |
| 67 int64 read_position_; | |
| 68 | |
| 69 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol); | |
| 70 }; | |
| 71 | |
| 72 } // namespace media | |
| 73 | |
| 74 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ | |
| OLD | NEW |