|
Lines 1-6
a/Source/WebCore/Modules/mediastream/MediaStream.cpp_sec1
|
| 1 |
/* |
1 |
/* |
| 2 |
* Copyright (C) 2011 Google Inc. All rights reserved. |
2 |
* Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 |
* Copyright (C) 2011 Ericsson AB. All rights reserved. |
3 |
* Copyright (C) 2011, 2012 Ericsson AB. All rights reserved. |
| 4 |
* |
4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without |
5 |
* Redistribution and use in source and binary forms, with or without |
| 6 |
* modification, are permitted provided that the following conditions |
6 |
* modification, are permitted provided that the following conditions |
|
Lines 36-82
a/Source/WebCore/Modules/mediastream/MediaStream.cpp_sec2
|
| 36 |
|
36 |
|
| 37 |
namespace WebCore { |
37 |
namespace WebCore { |
| 38 |
|
38 |
|
| 39 |
static void processTrackList(PassRefPtr<MediaStreamTrackList> prpTracks, const String& kind, MediaStreamSourceVector& sources, ExceptionCode& ec) |
39 |
static bool containsSource(MediaStreamSourceVector& sourceVector, MediaStreamSource* source) |
| 40 |
{ |
40 |
{ |
| 41 |
RefPtr<MediaStreamTrackList> tracks = prpTracks; |
41 |
for (size_t i = 0; i < sourceVector.size(); ++i) |
| 42 |
if (!tracks) |
42 |
if (source->id() == sourceVector[i]->id()) |
|
|
43 |
return true; |
| 44 |
return false; |
| 45 |
} |
| 46 |
|
| 47 |
static void processTrack(MediaStreamTrack* track, MediaStreamSourceVector& sourceVector) |
| 48 |
{ |
| 49 |
if (track->readyState() == MediaStreamTrack::ENDED) |
| 43 |
return; |
50 |
return; |
| 44 |
|
51 |
|
| 45 |
for (unsigned i = 0; i < tracks->length(); ++i) { |
52 |
MediaStreamSource* source = track->component()->source(); |
| 46 |
MediaStreamTrack* track = tracks->item(i); |
53 |
if (!containsSource(sourceVector, source)) |
| 47 |
if (track->kind() != kind) { |
54 |
sourceVector.append(source); |
| 48 |
ec = SYNTAX_ERR; |
55 |
} |
| 49 |
return; |
56 |
|
| 50 |
} |
57 |
static PassRefPtr<MediaStream> createFromSourceVectors(ScriptExecutionContext* context, const MediaStreamSourceVector& audioSources, const MediaStreamSourceVector& videoSources) |
| 51 |
MediaStreamSource* source = track->component()->source(); |
58 |
{ |
| 52 |
bool isDuplicate = false; |
59 |
RefPtr<MediaStreamDescriptor> descriptor = MediaStreamDescriptor::create(createCanonicalUUIDString(), audioSources, videoSources); |
| 53 |
for (MediaStreamSourceVector::iterator j = sources.begin(); j < sources.end(); ++j) { |
60 |
MediaStreamCenter::instance().didCreateMediaStream(descriptor.get()); |
| 54 |
if ((*j)->id() == source->id()) { |
61 |
|
| 55 |
isDuplicate = true; |
62 |
return MediaStream::create(context, descriptor.release()); |
| 56 |
break; |
63 |
} |
| 57 |
} |
64 |
|
| 58 |
} |
65 |
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context) |
| 59 |
if (!isDuplicate) |
66 |
{ |
| 60 |
sources.append(source); |
67 |
MediaStreamSourceVector audioSources; |
| 61 |
} |
68 |
MediaStreamSourceVector videoSources; |
|
|
69 |
|
| 70 |
return createFromSourceVectors(context, audioSources, videoSources); |
| 62 |
} |
71 |
} |
| 63 |
|
72 |
|
| 64 |
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context, PassRefPtr<MediaStreamTrackList> audioTracks, PassRefPtr<MediaStreamTrackList> videoTracks, ExceptionCode& ec) |
73 |
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context, PassRefPtr<MediaStream> stream) |
| 65 |
{ |
74 |
{ |
|
|
75 |
ASSERT(stream); |
| 76 |
|
| 66 |
MediaStreamSourceVector audioSources; |
77 |
MediaStreamSourceVector audioSources; |
| 67 |
processTrackList(audioTracks, "audio", audioSources, ec); |
78 |
MediaStreamSourceVector videoSources; |
| 68 |
if (ec) |
79 |
|
| 69 |
return 0; |
80 |
for (size_t i = 0; i < stream->audioTracks()->length(); ++i) |
|
|
81 |
processTrack(stream->audioTracks()->item(i), audioSources); |
| 82 |
|
| 83 |
for (size_t i = 0; i < stream->videoTracks()->length(); ++i) |
| 84 |
processTrack(stream->videoTracks()->item(i), videoSources); |
| 70 |
|
85 |
|
|
|
86 |
return createFromSourceVectors(context, audioSources, videoSources); |
| 87 |
} |
| 88 |
|
| 89 |
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context, const MediaStreamTrackVector& tracks) |
| 90 |
{ |
| 91 |
MediaStreamSourceVector audioSources; |
| 71 |
MediaStreamSourceVector videoSources; |
92 |
MediaStreamSourceVector videoSources; |
| 72 |
processTrackList(videoTracks, "video", videoSources, ec); |
|
|
| 73 |
if (ec) |
| 74 |
return 0; |
| 75 |
|
93 |
|
| 76 |
RefPtr<MediaStreamDescriptor> descriptor = MediaStreamDescriptor::create(createCanonicalUUIDString(), audioSources, videoSources); |
94 |
for (size_t i = 0; i < tracks.size(); ++i) |
| 77 |
MediaStreamCenter::instance().didCreateMediaStream(descriptor.get()); |
95 |
processTrack(tracks[i].get(), tracks[i]->kind() == "audio" ? audioSources : videoSources); |
| 78 |
|
96 |
|
| 79 |
return adoptRef(new MediaStream(context, descriptor.release())); |
97 |
return createFromSourceVectors(context, audioSources, videoSources); |
| 80 |
} |
98 |
} |
| 81 |
|
99 |
|
| 82 |
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor) |
100 |
PassRefPtr<MediaStream> MediaStream::create(ScriptExecutionContext* context, PassRefPtr<MediaStreamDescriptor> streamDescriptor) |