Chromium Code Reviews| 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_FILTERS_BLOCKING_URL_PROTOCOL_H_ | 5 #ifndef MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ |
| 6 #define MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ | 6 #define MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/synchronization/lock.h" | |
| 12 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
| 13 #include "media/filters/ffmpeg_glue.h" | 14 #include "media/filters/ffmpeg_glue.h" |
| 14 | 15 |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 class DataSource; | 18 class DataSource; |
| 18 | 19 |
| 19 // An implementation of FFmpegURLProtocol that blocks until the underlying | 20 // An implementation of FFmpegURLProtocol that blocks until the underlying |
| 20 // asynchronous DataSource::Read() operation completes. | 21 // asynchronous DataSource::Read() operation completes. |
|
xhwang
2017/02/23 23:45:42
nit: Can we have some documentation on the threadi
DaleCurtis
2017/02/24 23:40:29
Done.
| |
| 21 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol { | 22 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol { |
| 22 public: | 23 public: |
| 23 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is | 24 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is |
| 24 // fired any time DataSource::Read() returns an error. | 25 // fired any time DataSource::Read() returns an error. |
| 25 // | 26 // |
| 26 // TODO(scherkus): After all blocking operations are isolated on a separate | 27 // TODO(scherkus): After all blocking operations are isolated on a separate |
| 27 // thread we should be able to eliminate |error_cb|. | 28 // thread we should be able to eliminate |error_cb|. |
| 28 BlockingUrlProtocol(DataSource* data_source, const base::Closure& error_cb); | 29 BlockingUrlProtocol(DataSource* data_source, const base::Closure& error_cb); |
| 29 virtual ~BlockingUrlProtocol(); | 30 virtual ~BlockingUrlProtocol(); |
| 30 | 31 |
| 31 // Aborts any pending reads by returning a read error. After this method | 32 // Aborts any pending reads by returning a read error. After this method |
| 32 // returns all subsequent calls to Read() will immediately fail. | 33 // returns all subsequent calls to Read() will immediately fail. |
| 33 void Abort(); | 34 void Abort(); |
| 34 | 35 |
| 35 // FFmpegURLProtocol implementation. | 36 // FFmpegURLProtocol implementation. |
| 36 int Read(int size, uint8_t* data) override; | 37 int Read(int size, uint8_t* data) override; |
| 37 bool GetPosition(int64_t* position_out) override; | 38 bool GetPosition(int64_t* position_out) override; |
| 38 bool SetPosition(int64_t position) override; | 39 bool SetPosition(int64_t position) override; |
| 39 bool GetSize(int64_t* size_out) override; | 40 bool GetSize(int64_t* size_out) override; |
| 40 bool IsStreaming() override; | 41 bool IsStreaming() override; |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 // Sets |last_read_bytes_| and signals the blocked thread that the read | 44 // Sets |last_read_bytes_| and signals the blocked thread that the read |
| 44 // has completed. | 45 // has completed. |
| 45 void SignalReadCompleted(int size); | 46 void SignalReadCompleted(int size); |
| 46 | 47 |
| 48 base::Lock data_source_lock_; | |
|
xhwang
2017/02/23 23:45:42
Can you provide a comment why we need this lock, e
DaleCurtis
2017/02/24 23:40:29
Done.
| |
| 47 DataSource* data_source_; | 49 DataSource* data_source_; |
|
xhwang
2017/02/23 23:45:42
nit: add an empty line here so that it's more clea
DaleCurtis
2017/02/24 23:40:29
Done.
| |
| 48 base::Closure error_cb_; | 50 base::Closure error_cb_; |
| 51 const bool is_streaming_; | |
| 49 | 52 |
| 50 // Used to unblock the thread during shutdown and when reads complete. | 53 // Used to unblock the thread during shutdown and when reads complete. |
| 51 base::WaitableEvent aborted_; | 54 base::WaitableEvent aborted_; |
| 52 base::WaitableEvent read_complete_; | 55 base::WaitableEvent read_complete_; |
| 53 | 56 |
| 54 // Cached number of bytes last read from the data source. | 57 // Cached number of bytes last read from the data source. |
| 55 int last_read_bytes_; | 58 int last_read_bytes_; |
| 56 | 59 |
| 57 // Cached position within the data source. | 60 // Cached position within the data source. |
| 58 int64_t read_position_; | 61 int64_t read_position_; |
| 59 | 62 |
| 60 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol); | 63 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol); |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 } // namespace media | 66 } // namespace media |
| 64 | 67 |
| 65 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ | 68 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ |
| OLD | NEW |