Move UpdateManifest test from unit_tests into extensions_unittests.
[chromium-blink-merge.git] / media / filters / blocking_url_protocol.h
blobdbeeef917c327c9fd8f7e17f6162f78714261f15
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.
5 #ifndef MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_
6 #define MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "media/filters/ffmpeg_glue.h"
13 namespace media {
15 class DataSource;
17 // An implementation of FFmpegURLProtocol that blocks until the underlying
18 // asynchronous DataSource::Read() operation completes.
19 class MEDIA_EXPORT BlockingUrlProtocol : public FFmpegURLProtocol {
20 public:
21 // Implements FFmpegURLProtocol using the given |data_source|. |error_cb| is
22 // fired any time DataSource::Read() returns an error.
24 // TODO(scherkus): After all blocking operations are isolated on a separate
25 // thread we should be able to eliminate |error_cb|.
26 BlockingUrlProtocol(DataSource* data_source, const base::Closure& error_cb);
27 virtual ~BlockingUrlProtocol();
29 // Aborts any pending reads by returning a read error. After this method
30 // returns all subsequent calls to Read() will immediately fail.
31 void Abort();
33 // FFmpegURLProtocol implementation.
34 int Read(int size, uint8* data) override;
35 bool GetPosition(int64* position_out) override;
36 bool SetPosition(int64 position) override;
37 bool GetSize(int64* size_out) override;
38 bool IsStreaming() override;
40 private:
41 // Sets |last_read_bytes_| and signals the blocked thread that the read
42 // has completed.
43 void SignalReadCompleted(int size);
45 DataSource* data_source_;
46 base::Closure error_cb_;
48 // Used to unblock the thread during shutdown and when reads complete.
49 base::WaitableEvent aborted_;
50 base::WaitableEvent read_complete_;
52 // Cached number of bytes last read from the data source.
53 int last_read_bytes_;
55 // Cached position within the data source.
56 int64 read_position_;
58 DISALLOW_IMPLICIT_CONSTRUCTORS(BlockingUrlProtocol);
61 } // namespace media
63 #endif // MEDIA_FILTERS_BLOCKING_URL_PROTOCOL_H_