Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: media/base/stream_parser.cc

Issue 149153002: MSE: Add StreamParser buffer remuxing utility and tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Attempt windows stream_parser_unittests compilation fix Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/stream_parser.h" 5 #include "media/base/stream_parser.h"
6 6
7 #include "media/base/buffers.h"
8 #include "media/base/stream_parser_buffer.h"
9
7 namespace media { 10 namespace media {
8 11
9 StreamParser::StreamParser() {} 12 StreamParser::StreamParser() {}
10 13
11 StreamParser::~StreamParser() {} 14 StreamParser::~StreamParser() {}
12 15
16 bool StreamParser::MergeBufferQueues(const BufferQueue& audio_buffers,
xhwang 2014/01/29 08:04:50 This function doesn't use any member variable. Doe
wolenetz 2014/02/05 02:49:53 Yeah, there's really no need other than possibly n
17 const BufferQueue& video_buffers,
18 const TextBufferQueueMap& text_buffers,
19 BufferQueue* merged_buffers) {
20 DCHECK(merged_buffers);
21
22 // Prepare vector containing pointers to any provided non-empty buffer queues.
23 std::vector<const BufferQueue*> buffer_queues;
24 if (!audio_buffers.empty())
25 buffer_queues.push_back(&audio_buffers);
26 if (!video_buffers.empty())
27 buffer_queues.push_back(&video_buffers);
28 for (TextBufferQueueMap::const_iterator map_itr = text_buffers.begin();
29 map_itr != text_buffers.end();
30 map_itr++) {
31 if (!map_itr->second.empty())
32 buffer_queues.push_back(&(map_itr->second));
33 }
34
35 // Do the merge.
36 return MergeBufferQueues(buffer_queues, merged_buffers);
37 }
38
39 bool
40 StreamParser::MergeBufferQueues(std::vector<const BufferQueue*> buffer_queues,
xhwang 2014/01/29 08:04:50 The implementation is complicated, we may need mor
wolenetz 2014/02/05 02:49:53 I've added more documentation now. We'd need to h
41 BufferQueue* merged_buffers) {
xhwang 2014/01/29 08:04:50 format looks odd; put bool and function name in th
wolenetz 2014/02/05 02:49:53 Done.
42 if (buffer_queues.empty())
43 return true;
44
45 std::vector<BufferQueue::const_iterator> itrs;
46 for (size_t i = 0; i < buffer_queues.size(); ++i)
47 itrs.push_back(buffer_queues[i]->begin());
48
49 base::TimeDelta last_timestamp = kNoTimestamp();
50 if (!merged_buffers->empty())
51 last_timestamp = merged_buffers->back()->GetDecodeTimestamp();
52
53 while (true) {
54 int index_of_queue_with_next_timestamp = -1;
55 base::TimeDelta next_timestamp = kNoTimestamp();
56
57 for (size_t i = 0; i < buffer_queues.size(); ++i) {
58 if (itrs[i] != buffer_queues[i]->end()) {
59 base::TimeDelta ts = (*itrs[i])->GetDecodeTimestamp();
60
61 if (last_timestamp != kNoTimestamp() && ts < last_timestamp)
62 return false;
63
64 if (ts < next_timestamp || next_timestamp == kNoTimestamp()) {
65 next_timestamp = ts;
66 index_of_queue_with_next_timestamp = i;
67 }
68 }
69 }
70
71 if (index_of_queue_with_next_timestamp == -1)
72 return true;
73
74 scoped_refptr<StreamParserBuffer> buffer =
75 *itrs[index_of_queue_with_next_timestamp];
76 last_timestamp = buffer->GetDecodeTimestamp();
77 merged_buffers->push_back(buffer);
78 ++itrs[index_of_queue_with_next_timestamp];
79 }
80 }
81
13 } // namespace media 82 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698