aura: Remove more code that explicitly creates/destroys aura::Env.
[chromium-blink-merge.git] / media / blink / webmediasource_impl.cc
blob4760a49c042c8b8cbd4d13cd4842b507f7963027
1 // Copyright 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 "media/blink/webmediasource_impl.h"
7 #include "base/guid.h"
8 #include "media/blink/websourcebuffer_impl.h"
9 #include "media/filters/chunk_demuxer.h"
10 #include "third_party/WebKit/public/platform/WebCString.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
13 using ::blink::WebString;
14 using ::blink::WebMediaSource;
16 namespace media {
18 #define STATIC_ASSERT_MATCHING_STATUS_ENUM(webkit_name, chromium_name) \
19 static_assert(static_cast<int>(WebMediaSource::webkit_name) == \
20 static_cast<int>(ChunkDemuxer::chromium_name), \
21 "mismatching status enum values: " #webkit_name)
22 STATIC_ASSERT_MATCHING_STATUS_ENUM(AddStatusOk, kOk);
23 STATIC_ASSERT_MATCHING_STATUS_ENUM(AddStatusNotSupported, kNotSupported);
24 STATIC_ASSERT_MATCHING_STATUS_ENUM(AddStatusReachedIdLimit, kReachedIdLimit);
25 #undef STATIC_ASSERT_MATCHING_STATUS_ENUM
27 WebMediaSourceImpl::WebMediaSourceImpl(ChunkDemuxer* demuxer,
28 const scoped_refptr<MediaLog>& media_log)
29 : demuxer_(demuxer), media_log_(media_log) {
30 DCHECK(demuxer_);
33 WebMediaSourceImpl::~WebMediaSourceImpl() {}
35 WebMediaSource::AddStatus WebMediaSourceImpl::addSourceBuffer(
36 const blink::WebString& type,
37 const blink::WebVector<blink::WebString>& codecs,
38 blink::WebSourceBuffer** source_buffer) {
39 std::string id = base::GenerateGUID();
40 std::vector<std::string> new_codecs(codecs.size());
41 for (size_t i = 0; i < codecs.size(); ++i)
42 new_codecs[i] = codecs[i].utf8().data();
44 WebMediaSource::AddStatus result =
45 static_cast<WebMediaSource::AddStatus>(
46 demuxer_->AddId(id, type.utf8().data(), new_codecs));
48 if (result == WebMediaSource::AddStatusOk)
49 *source_buffer = new WebSourceBufferImpl(id, demuxer_);
51 return result;
54 double WebMediaSourceImpl::duration() {
55 return demuxer_->GetDuration();
58 void WebMediaSourceImpl::setDuration(double new_duration) {
59 DCHECK_GE(new_duration, 0);
60 demuxer_->SetDuration(new_duration);
63 void WebMediaSourceImpl::markEndOfStream(
64 WebMediaSource::EndOfStreamStatus status) {
65 PipelineStatus pipeline_status = PIPELINE_OK;
67 switch (status) {
68 case WebMediaSource::EndOfStreamStatusNoError:
69 break;
70 case WebMediaSource::EndOfStreamStatusNetworkError:
71 pipeline_status = PIPELINE_ERROR_NETWORK;
72 break;
73 case WebMediaSource::EndOfStreamStatusDecodeError:
74 pipeline_status = PIPELINE_ERROR_DECODE;
75 break;
78 demuxer_->MarkEndOfStream(pipeline_status);
81 void WebMediaSourceImpl::unmarkEndOfStream() {
82 demuxer_->UnmarkEndOfStream();
85 } // namespace media