blob: 75772373ed7f5b8f84f3d7c4d7522dd8437f11c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_DATA_SOURCE_H_
#define MEDIA_BASE_DATA_SOURCE_H_
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "media/base/media_export.h"
#include "media/base/preload.h"
namespace media {
class MEDIA_EXPORT DataSourceHost {
public:
virtual ~DataSourceHost();
// Set the total size of the media file.
virtual void SetTotalBytes(int64 total_bytes) = 0;
// Sets the total number of bytes that are buffered on the client and ready to
// be played.
virtual void SetBufferedBytes(int64 buffered_bytes) = 0;
// Sets the flag to indicate current network activity.
virtual void SetNetworkActivity(bool is_downloading_data) = 0;
};
class MEDIA_EXPORT DataSource : public base::RefCountedThreadSafe<DataSource> {
public:
typedef base::Callback<void(int64, int64)> StatusCallback;
typedef base::Callback<void(size_t)> ReadCB;
static const size_t kReadError;
DataSource();
virtual void set_host(DataSourceHost* host);
// Reads |size| bytes from |position| into |data|. And when the read is done
// or failed, |read_cb| is called with the number of bytes read or
// kReadError in case of error.
// TODO(hclam): should change |size| to int! It makes the code so messy
// with size_t and int all over the place..
virtual void Read(int64 position, size_t size,
uint8* data,
const DataSource::ReadCB& read_cb) = 0;
// Notifies the DataSource of a change in the current playback rate.
virtual void SetPlaybackRate(float playback_rate);
// Stops the DataSource. Once this is called all future Read() calls will
// return an error.
virtual void Stop(const base::Closure& callback) = 0;
// Returns true and the file size, false if the file size could not be
// retrieved.
virtual bool GetSize(int64* size_out) = 0;
// Returns true if we are performing streaming. In this case seeking is
// not possible.
virtual bool IsStreaming() = 0;
// Alert the DataSource that the video preload value has been changed.
virtual void SetPreload(Preload preload) = 0;
// Notify the DataSource of the bitrate of the media.
// Values of |bitrate| <= 0 are invalid and should be ignored.
virtual void SetBitrate(int bitrate) = 0;
protected:
// Only allow scoped_refptr<> to delete DataSource.
friend class base::RefCountedThreadSafe<DataSource>;
virtual ~DataSource();
DataSourceHost* host();
private:
DataSourceHost* host_;
DISALLOW_COPY_AND_ASSIGN(DataSource);
};
} // namespace media
#endif // MEDIA_BASE_DATA_SOURCE_H_
|