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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
// Copyright (c) 2011 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.
// An extremely simple implementation of DataSource that downloads the entire
// media resource into memory before signaling that initialization has finished.
// Primarily used to test <audio> and <video> with buffering/caching removed
// from the equation.
#ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
#define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
#include <algorithm>
#include <string>
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "media/base/filter_factories.h"
#include "media/base/filters.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h"
#include "webkit/glue/media/web_data_source.h"
class MessageLoop;
class WebMediaPlayerDelegateImpl;
namespace media {
class MediaLog;
}
namespace webkit_glue {
class SimpleDataSource
: public WebDataSource,
public WebKit::WebURLLoaderClient {
public:
// Creates a DataSourceFactory for building SimpleDataSource objects.
static media::DataSourceFactory* CreateFactory(
MessageLoop* render_loop,
WebKit::WebFrame* frame,
media::MediaLog* media_log,
const WebDataSourceBuildObserverHack& build_observer);
SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame);
virtual ~SimpleDataSource();
// media::Filter implementation.
virtual void set_host(media::FilterHost* host);
virtual void Stop(const base::Closure& callback);
// media::DataSource implementation.
virtual void Read(int64 position, size_t size,
uint8* data, const DataSource::ReadCallback& read_callback);
virtual bool GetSize(int64* size_out);
virtual bool IsStreaming();
virtual void SetPreload(media::Preload preload);
virtual void SetBitrate(int bitrate);
// Used to inject a mock used for unittests.
virtual void SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader);
// WebKit::WebURLLoaderClient implementations.
virtual void willSendRequest(
WebKit::WebURLLoader* loader,
WebKit::WebURLRequest& newRequest,
const WebKit::WebURLResponse& redirectResponse);
virtual void didSendData(
WebKit::WebURLLoader* loader,
unsigned long long bytesSent,
unsigned long long totalBytesToBeSent);
virtual void didReceiveResponse(
WebKit::WebURLLoader* loader,
const WebKit::WebURLResponse& response);
virtual void didDownloadData(
WebKit::WebURLLoader* loader,
int dataLength);
virtual void didReceiveData(
WebKit::WebURLLoader* loader,
const char* data,
int dataLength,
int encodedDataLength);
virtual void didReceiveCachedMetadata(
WebKit::WebURLLoader* loader,
const char* data, int dataLength);
virtual void didFinishLoading(
WebKit::WebURLLoader* loader,
double finishTime);
virtual void didFail(
WebKit::WebURLLoader* loader,
const WebKit::WebURLError&);
// webkit_glue::WebDataSource implementation.
virtual void Initialize(const std::string& url,
const media::PipelineStatusCB& callback);
virtual void CancelInitialize();
virtual bool HasSingleOrigin();
virtual void Abort();
private:
// Creates and starts the resource loading on the render thread.
void StartTask();
// Cancels and deletes the resource loading on the render thread.
void CancelTask();
// Perform initialization completion tasks under a lock.
void DoneInitialization_Locked(bool success);
// Update host() stats like total bytes & buffered bytes.
void UpdateHostState();
// Primarily used for asserting the bridge is loading on the render thread.
MessageLoop* render_loop_;
// A webframe for loading.
WebKit::WebFrame* frame_;
// Does the work of loading and sends data back to this client.
scoped_ptr<WebKit::WebURLLoader> url_loader_;
GURL url_;
std::string data_;
int64 size_;
bool single_origin_;
// Simple state tracking variable.
enum State {
UNINITIALIZED,
INITIALIZING,
INITIALIZED,
STOPPED,
};
State state_;
// Used for accessing |state_|.
base::Lock lock_;
// Filter callbacks.
media::PipelineStatusCB initialize_cb_;
// Used to ensure mocks for unittests are used instead of reset in Start().
bool keep_test_loader_;
DISALLOW_COPY_AND_ASSIGN(SimpleDataSource);
};
} // namespace webkit_glue
#endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
|