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
|
// Copyright (c) 2013 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.
#include "webkit/media/webmediasourceclient_impl.h"
#include "base/guid.h"
#include "media/filters/chunk_demuxer.h"
#include "third_party/WebKit/public/platform/WebCString.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "webkit/media/websourcebuffer_impl.h"
using ::WebKit::WebString;
using ::WebKit::WebMediaSourceClient;
namespace webkit_media {
#define COMPILE_ASSERT_MATCHING_STATUS_ENUM(webkit_name, chromium_name) \
COMPILE_ASSERT(static_cast<int>(WebMediaSourceClient::webkit_name) == \
static_cast<int>(media::ChunkDemuxer::chromium_name), \
mismatching_status_enums)
COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddStatusOk, kOk);
COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddStatusNotSupported, kNotSupported);
COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddStatusReachedIdLimit, kReachedIdLimit);
#undef COMPILE_ASSERT_MATCHING_STATUS_ENUM
WebMediaSourceClientImpl::WebMediaSourceClientImpl(
media::ChunkDemuxer* demuxer, media::LogCB log_cb)
: demuxer_(demuxer),
log_cb_(log_cb) {
DCHECK(demuxer_);
}
WebMediaSourceClientImpl::~WebMediaSourceClientImpl() {}
WebMediaSourceClient::AddStatus WebMediaSourceClientImpl::addSourceBuffer(
const WebKit::WebString& type,
const WebKit::WebVector<WebKit::WebString>& codecs,
WebKit::WebSourceBuffer** source_buffer) {
std::string id = base::GenerateGUID();
std::vector<std::string> new_codecs(codecs.size());
for (size_t i = 0; i < codecs.size(); ++i)
new_codecs[i] = codecs[i].utf8().data();
WebMediaSourceClient::AddStatus result =
static_cast<WebMediaSourceClient::AddStatus>(
demuxer_->AddId(id, type.utf8().data(), new_codecs));
if (result == WebMediaSourceClient::AddStatusOk)
*source_buffer = new WebSourceBufferImpl(id, demuxer_);
return result;
}
double WebMediaSourceClientImpl::duration() {
return demuxer_->GetDuration();
}
void WebMediaSourceClientImpl::setDuration(double new_duration) {
DCHECK_GE(new_duration, 0);
demuxer_->SetDuration(new_duration);
}
void WebMediaSourceClientImpl::endOfStream(
WebMediaSourceClient::EndOfStreamStatus status) {
media::PipelineStatus pipeline_status = media::PIPELINE_OK;
switch (status) {
case WebMediaSourceClient::EndOfStreamStatusNoError:
break;
case WebMediaSourceClient::EndOfStreamStatusNetworkError:
pipeline_status = media::PIPELINE_ERROR_NETWORK;
break;
case WebMediaSourceClient::EndOfStreamStatusDecodeError:
pipeline_status = media::PIPELINE_ERROR_DECODE;
break;
default:
NOTIMPLEMENTED();
}
if (!demuxer_->EndOfStream(pipeline_status))
DVLOG(1) << "EndOfStream call failed.";
}
} // namespace webkit_media
|