Fix Win8 metro startup crash from window switcher button
[chromium-blink-merge.git] / webkit / media / webmediasourceclient_impl.cc
blob3eb36f46587f0ab520b78e8dfbacd6b09115cea0
1 // Copyright (c) 2013 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 #include "webkit/media/webmediasourceclient_impl.h"
7 #include "base/guid.h"
8 #include "media/filters/chunk_demuxer.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
11 #include "webkit/media/websourcebuffer_impl.h"
13 using ::WebKit::WebString;
14 using ::WebKit::WebMediaSourceClient;
16 namespace webkit_media {
18 #define COMPILE_ASSERT_MATCHING_STATUS_ENUM(webkit_name, chromium_name) \
19 COMPILE_ASSERT(static_cast<int>(WebMediaSourceClient::webkit_name) == \
20 static_cast<int>(media::ChunkDemuxer::chromium_name), \
21 mismatching_status_enums)
22 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddStatusOk, kOk);
23 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddStatusNotSupported, kNotSupported);
24 COMPILE_ASSERT_MATCHING_STATUS_ENUM(AddStatusReachedIdLimit, kReachedIdLimit);
25 #undef COMPILE_ASSERT_MATCHING_STATUS_ENUM
27 WebMediaSourceClientImpl::WebMediaSourceClientImpl(
28 media::ChunkDemuxer* demuxer, media::LogCB log_cb)
29 : demuxer_(demuxer),
30 log_cb_(log_cb) {
31 DCHECK(demuxer_);
34 WebMediaSourceClientImpl::~WebMediaSourceClientImpl() {}
36 WebMediaSourceClient::AddStatus WebMediaSourceClientImpl::addSourceBuffer(
37 const WebKit::WebString& type,
38 const WebKit::WebVector<WebKit::WebString>& codecs,
39 WebKit::WebSourceBuffer** source_buffer) {
40 std::string id = base::GenerateGUID();
41 std::vector<std::string> new_codecs(codecs.size());
42 for (size_t i = 0; i < codecs.size(); ++i)
43 new_codecs[i] = codecs[i].utf8().data();
44 WebMediaSourceClient::AddStatus result =
45 static_cast<WebMediaSourceClient::AddStatus>(
46 demuxer_->AddId(id, type.utf8().data(), new_codecs));
48 if (result == WebMediaSourceClient::AddStatusOk)
49 *source_buffer = new WebSourceBufferImpl(id, demuxer_);
51 return result;
54 double WebMediaSourceClientImpl::duration() {
55 return demuxer_->GetDuration();
58 void WebMediaSourceClientImpl::setDuration(double new_duration) {
59 DCHECK_GE(new_duration, 0);
60 demuxer_->SetDuration(new_duration);
63 void WebMediaSourceClientImpl::endOfStream(
64 WebMediaSourceClient::EndOfStreamStatus status) {
65 media::PipelineStatus pipeline_status = media::PIPELINE_OK;
67 switch (status) {
68 case WebMediaSourceClient::EndOfStreamStatusNoError:
69 break;
70 case WebMediaSourceClient::EndOfStreamStatusNetworkError:
71 pipeline_status = media::PIPELINE_ERROR_NETWORK;
72 break;
73 case WebMediaSourceClient::EndOfStreamStatusDecodeError:
74 pipeline_status = media::PIPELINE_ERROR_DECODE;
75 break;
76 default:
77 NOTIMPLEMENTED();
80 if (!demuxer_->EndOfStream(pipeline_status))
81 DVLOG(1) << "EndOfStream call failed.";
84 } // namespace webkit_media