Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: media/filters/blocking_url_protocol.h

Issue 2710133003: Replace FFmpegDemuxer thread per element with base::TaskScheduler. (Closed)
Patch Set: Give WeakPtr to URLProtocol. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. Generally constructed on
22 // the media thread and used by ffmpeg through the AVIO interface from a
23 // sequenced blocking pool.
21 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol { 24 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol {
22 public: 25 public:
23 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is 26 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is
24 // fired any time DataSource::Read() returns an error. 27 // fired any time DataSource::Read() returns an error.
25 //
26 // TODO(scherkus): After all blocking operations are isolated on a separate
27 // thread we should be able to eliminate |error_cb|.
28 BlockingUrlProtocol(DataSource* data_source, const base::Closure& error_cb); 28 BlockingUrlProtocol(DataSource* data_source, const base::Closure& error_cb);
29 virtual ~BlockingUrlProtocol(); 29 virtual ~BlockingUrlProtocol();
30 30
31 // Aborts any pending reads by returning a read error. After this method 31 // Aborts any pending reads by returning a read error. After this method
32 // returns all subsequent calls to Read() will immediately fail. 32 // returns all subsequent calls to Read() will immediately fail. May be called
33 // from any thread and upon return ensures no further use of |data_source_|.
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 // |data_source_lock_| allows Abort() to be called from any thread and stop
49 // all outstanding access to |data_source_|. Typically Abort() is called from
50 // the media thread while ffmpeg is operating on another thread.
51 base::Lock data_source_lock_;
47 DataSource* data_source_; 52 DataSource* data_source_;
53
48 base::Closure error_cb_; 54 base::Closure error_cb_;
55 const bool is_streaming_;
49 56
50 // Used to unblock the thread during shutdown and when reads complete. 57 // Used to unblock the thread during shutdown and when reads complete.
51 base::WaitableEvent aborted_; 58 base::WaitableEvent aborted_;
52 base::WaitableEvent read_complete_; 59 base::WaitableEvent read_complete_;
53 60
54 // Cached number of bytes last read from the data source. 61 // Cached number of bytes last read from the data source.
55 int last_read_bytes_; 62 int last_read_bytes_;
56 63
57 // Cached position within the data source. 64 // Cached position within the data source.
58 int64_t read_position_; 65 int64_t read_position_;
59 66
60 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol); 67 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol);
61 }; 68 };
62 69
63 } // namespace media 70 } // namespace media
64 71
65 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ 72 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698