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

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

Issue 11410052: Refactor FFmpegURLProtocol code from FFmpegDemuxer into BlockingUrlProtocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(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/synchronization/waitable_event.h"
11 #include "media/filters/ffmpeg_glue.h"
12
13 namespace media {
14
15 class DataSource;
16
17 // An implementation of FFmpegURLProtocol that blocks until the underlying
18 // asynchronous DataSource::Read() operation completes.
19 //
20 // TODO(scherkus): Should be more thread-safe as |last_read_bytes_| is updated
21 // from multiple threads without any protection.
22 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol {
23 public:
24 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is
25 // fired any time DataSource::Read() returns an error.
26 //
27 // TODO(scherkus): After all blocking operations are isolated on a separate
28 // thread we should be able to eliminate |error_cb|.
29 BlockingUrlProtocol(const scoped_refptr<DataSource>& data_source,
30 const base::Closure& error_cb);
31 virtual ~BlockingUrlProtocol();
32
33 // Aborts any pending reads by returning a read error. After this method
34 // returns all subsequent calls to Read() will immediately fail.
35 //
36 // TODO(scherkus): Currently this will cause |error_cb| to fire. Fix.
37 void Abort();
38
39 // FFmpegURLProtocol implementation.
40 virtual int Read(int size, uint8* data) OVERRIDE;
41 virtual bool GetPosition(int64* position_out) OVERRIDE;
42 virtual bool SetPosition(int64 position) OVERRIDE;
43 virtual bool GetSize(int64* size_out) OVERRIDE;
44 virtual bool IsStreaming() OVERRIDE;
45
46 private:
47 // Sets |last_read_bytes_| and signals the blocked thread that the read
48 // has completed.
49 void SignalReadCompleted(int size);
50
51 scoped_refptr<DataSource> data_source_;
52 base::Closure error_cb_;
53
54 // Used to convert an asynchronous DataSource::Read() into a blocking
55 // FFmpegUrlProtocol::Read().
56 base::WaitableEvent read_event_;
57
58 // Read errors and aborts are unrecoverable. Any subsequent reads will
59 // immediately fail when this is set to true.
60 bool read_has_failed_;
61
62 // Cached number of bytes last read from the data source.
63 int last_read_bytes_;
64
65 // Cached position within the data source.
66 int64 read_position_;
67
68 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol);
69 };
70
71 } // namespace media
72
73 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_
OLDNEW
« no previous file with comments | « no previous file | media/filters/blocking_url_protocol.cc » ('j') | media/filters/blocking_url_protocol.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698