| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/renderer/media/webmediasource_impl.h" | |
| 6 | |
| 7 #include "base/guid.h" | |
| 8 #include "content/renderer/media/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" | |
| 12 | |
| 13 using ::blink::WebString; | |
| 14 using ::blink::WebMediaSource; | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 #define COMPILE_ASSERT_MATCHING_STATUS_ENUM(webkit_name, chromium_name) \ | |
| 19 COMPILE_ASSERT(static_cast<int>(WebMediaSource::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 | |
| 26 | |
| 27 WebMediaSourceImpl::WebMediaSourceImpl( | |
| 28 media::ChunkDemuxer* demuxer, media::LogCB log_cb) | |
| 29 : demuxer_(demuxer), | |
| 30 log_cb_(log_cb) { | |
| 31 DCHECK(demuxer_); | |
| 32 } | |
| 33 | |
| 34 WebMediaSourceImpl::~WebMediaSourceImpl() {} | |
| 35 | |
| 36 WebMediaSource::AddStatus WebMediaSourceImpl::addSourceBuffer( | |
| 37 const blink::WebString& type, | |
| 38 const blink::WebVector<blink::WebString>& codecs, | |
| 39 blink::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 | |
| 45 WebMediaSource::AddStatus result = | |
| 46 static_cast<WebMediaSource::AddStatus>( | |
| 47 demuxer_->AddId(id, type.utf8().data(), new_codecs)); | |
| 48 | |
| 49 if (result == WebMediaSource::AddStatusOk) | |
| 50 *source_buffer = new WebSourceBufferImpl(id, demuxer_); | |
| 51 | |
| 52 return result; | |
| 53 } | |
| 54 | |
| 55 double WebMediaSourceImpl::duration() { | |
| 56 return demuxer_->GetDuration(); | |
| 57 } | |
| 58 | |
| 59 void WebMediaSourceImpl::setDuration(double new_duration) { | |
| 60 DCHECK_GE(new_duration, 0); | |
| 61 demuxer_->SetDuration(new_duration); | |
| 62 } | |
| 63 | |
| 64 void WebMediaSourceImpl::markEndOfStream( | |
| 65 WebMediaSource::EndOfStreamStatus status) { | |
| 66 media::PipelineStatus pipeline_status = media::PIPELINE_OK; | |
| 67 | |
| 68 switch (status) { | |
| 69 case WebMediaSource::EndOfStreamStatusNoError: | |
| 70 break; | |
| 71 case WebMediaSource::EndOfStreamStatusNetworkError: | |
| 72 pipeline_status = media::PIPELINE_ERROR_NETWORK; | |
| 73 break; | |
| 74 case WebMediaSource::EndOfStreamStatusDecodeError: | |
| 75 pipeline_status = media::PIPELINE_ERROR_DECODE; | |
| 76 break; | |
| 77 } | |
| 78 | |
| 79 demuxer_->MarkEndOfStream(pipeline_status); | |
| 80 } | |
| 81 | |
| 82 void WebMediaSourceImpl::unmarkEndOfStream() { | |
| 83 demuxer_->UnmarkEndOfStream(); | |
| 84 } | |
| 85 | |
| 86 } // namespace content | |
| OLD | NEW |