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

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

Issue 2738503005: Created battor.tough_energy_cases (without dcurtis's change)
Patch Set: Reupload 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
« no previous file with comments | « media/base/demuxer_perftest.cc ('k') | media/filters/blocking_url_protocol.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
13 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
14 #include "media/filters/ffmpeg_glue.h" 13 #include "media/filters/ffmpeg_glue.h"
15 14
16 namespace media { 15 namespace media {
17 16
18 class DataSource; 17 class DataSource;
19 18
20 // An implementation of FFmpegURLProtocol that blocks until the underlying 19 // An implementation of FFmpegURLProtocol that blocks until the underlying
21 // asynchronous DataSource::Read() operation completes. Generally constructed on 20 // asynchronous DataSource::Read() operation completes.
22 // the media thread and used by ffmpeg through the AVIO interface from a
23 // sequenced blocking pool.
24 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol { 21 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol {
25 public: 22 public:
26 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is 23 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is
27 // fired any time DataSource::Read() returns an error. 24 // 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. May be called 32 // returns all subsequent calls to Read() will immediately fail.
33 // from any thread and upon return ensures no further use of |data_source_|.
34 void Abort(); 33 void Abort();
35 34
36 // FFmpegURLProtocol implementation. 35 // FFmpegURLProtocol implementation.
37 int Read(int size, uint8_t* data) override; 36 int Read(int size, uint8_t* data) override;
38 bool GetPosition(int64_t* position_out) override; 37 bool GetPosition(int64_t* position_out) override;
39 bool SetPosition(int64_t position) override; 38 bool SetPosition(int64_t position) override;
40 bool GetSize(int64_t* size_out) override; 39 bool GetSize(int64_t* size_out) override;
41 bool IsStreaming() override; 40 bool IsStreaming() override;
42 41
43 private: 42 private:
44 // Sets |last_read_bytes_| and signals the blocked thread that the read 43 // Sets |last_read_bytes_| and signals the blocked thread that the read
45 // has completed. 44 // has completed.
46 void SignalReadCompleted(int size); 45 void SignalReadCompleted(int size);
47 46
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_;
52 DataSource* data_source_; 47 DataSource* data_source_;
53
54 base::Closure error_cb_; 48 base::Closure error_cb_;
55 const bool is_streaming_;
56 49
57 // Used to unblock the thread during shutdown and when reads complete. 50 // Used to unblock the thread during shutdown and when reads complete.
58 base::WaitableEvent aborted_; 51 base::WaitableEvent aborted_;
59 base::WaitableEvent read_complete_; 52 base::WaitableEvent read_complete_;
60 53
61 // Cached number of bytes last read from the data source. 54 // Cached number of bytes last read from the data source.
62 int last_read_bytes_; 55 int last_read_bytes_;
63 56
64 // Cached position within the data source. 57 // Cached position within the data source.
65 int64_t read_position_; 58 int64_t read_position_;
66 59
67 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol); 60 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol);
68 }; 61 };
69 62
70 } // namespace media 63 } // namespace media
71 64
72 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_ 65 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_
OLDNEW
« no previous file with comments | « media/base/demuxer_perftest.cc ('k') | media/filters/blocking_url_protocol.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698