ATSParser.cpp revision decd96988e495133e4a1728f612d4c9fdb4d218e
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define LOG_NDEBUG 0 18#define LOG_TAG "ATSParser" 19#include <utils/Log.h> 20 21#include "ATSParser.h" 22 23#include "AnotherPacketSource.h" 24#include "ESQueue.h" 25#include "include/avc_utils.h" 26 27#include <media/stagefright/foundation/ABitReader.h> 28#include <media/stagefright/foundation/ABuffer.h> 29#include <media/stagefright/foundation/ADebug.h> 30#include <media/stagefright/foundation/AMessage.h> 31#include <media/stagefright/foundation/hexdump.h> 32#include <media/stagefright/MediaDefs.h> 33#include <media/stagefright/MediaErrors.h> 34#include <media/stagefright/MetaData.h> 35#include <utils/KeyedVector.h> 36 37namespace android { 38 39// I want the expression "y" evaluated even if verbose logging is off. 40#define MY_LOGV(x, y) \ 41 do { unsigned tmp = y; LOGV(x, tmp); } while (0) 42 43static const size_t kTSPacketSize = 188; 44 45struct ATSParser::Program : public RefBase { 46 Program(unsigned programMapPID); 47 48 bool parsePID( 49 unsigned pid, unsigned payload_unit_start_indicator, 50 ABitReader *br); 51 52 void signalDiscontinuity(bool isASeek); 53 54 sp<MediaSource> getSource(SourceType type); 55 56 int64_t convertPTSToTimestamp(uint64_t PTS); 57 58private: 59 unsigned mProgramMapPID; 60 KeyedVector<unsigned, sp<Stream> > mStreams; 61 bool mFirstPTSValid; 62 uint64_t mFirstPTS; 63 64 void parseProgramMap(ABitReader *br); 65 66 DISALLOW_EVIL_CONSTRUCTORS(Program); 67}; 68 69struct ATSParser::Stream : public RefBase { 70 Stream(Program *program, unsigned elementaryPID, unsigned streamType); 71 72 void parse( 73 unsigned payload_unit_start_indicator, 74 ABitReader *br); 75 76 void signalDiscontinuity(bool isASeek); 77 78 sp<MediaSource> getSource(SourceType type); 79 80protected: 81 virtual ~Stream(); 82 83private: 84 Program *mProgram; 85 unsigned mElementaryPID; 86 unsigned mStreamType; 87 88 sp<ABuffer> mBuffer; 89 sp<AnotherPacketSource> mSource; 90 bool mPayloadStarted; 91 92 ElementaryStreamQueue mQueue; 93 94 void flush(); 95 void parsePES(ABitReader *br); 96 97 void onPayloadData( 98 unsigned PTS_DTS_flags, uint64_t PTS, uint64_t DTS, 99 const uint8_t *data, size_t size); 100 101 void extractAACFrames(const sp<ABuffer> &buffer); 102 103 DISALLOW_EVIL_CONSTRUCTORS(Stream); 104}; 105 106//////////////////////////////////////////////////////////////////////////////// 107 108ATSParser::Program::Program(unsigned programMapPID) 109 : mProgramMapPID(programMapPID), 110 mFirstPTSValid(false), 111 mFirstPTS(0) { 112} 113 114bool ATSParser::Program::parsePID( 115 unsigned pid, unsigned payload_unit_start_indicator, 116 ABitReader *br) { 117 if (pid == mProgramMapPID) { 118 if (payload_unit_start_indicator) { 119 unsigned skip = br->getBits(8); 120 br->skipBits(skip * 8); 121 } 122 123 parseProgramMap(br); 124 return true; 125 } 126 127 ssize_t index = mStreams.indexOfKey(pid); 128 if (index < 0) { 129 return false; 130 } 131 132 mStreams.editValueAt(index)->parse( 133 payload_unit_start_indicator, br); 134 135 return true; 136} 137 138void ATSParser::Program::signalDiscontinuity(bool isASeek) { 139 for (size_t i = 0; i < mStreams.size(); ++i) { 140 mStreams.editValueAt(i)->signalDiscontinuity(isASeek); 141 } 142} 143 144void ATSParser::Program::parseProgramMap(ABitReader *br) { 145 unsigned table_id = br->getBits(8); 146 LOGV(" table_id = %u", table_id); 147 CHECK_EQ(table_id, 0x02u); 148 149 unsigned section_syntax_indicator = br->getBits(1); 150 LOGV(" section_syntax_indicator = %u", section_syntax_indicator); 151 CHECK_EQ(section_syntax_indicator, 1u); 152 153 CHECK_EQ(br->getBits(1), 0u); 154 MY_LOGV(" reserved = %u", br->getBits(2)); 155 156 unsigned section_length = br->getBits(12); 157 LOGV(" section_length = %u", section_length); 158 CHECK((section_length & 0xc00) == 0); 159 CHECK_LE(section_length, 1021u); 160 161 MY_LOGV(" program_number = %u", br->getBits(16)); 162 MY_LOGV(" reserved = %u", br->getBits(2)); 163 MY_LOGV(" version_number = %u", br->getBits(5)); 164 MY_LOGV(" current_next_indicator = %u", br->getBits(1)); 165 MY_LOGV(" section_number = %u", br->getBits(8)); 166 MY_LOGV(" last_section_number = %u", br->getBits(8)); 167 MY_LOGV(" reserved = %u", br->getBits(3)); 168 MY_LOGV(" PCR_PID = 0x%04x", br->getBits(13)); 169 MY_LOGV(" reserved = %u", br->getBits(4)); 170 171 unsigned program_info_length = br->getBits(12); 172 LOGV(" program_info_length = %u", program_info_length); 173 CHECK((program_info_length & 0xc00) == 0); 174 175 br->skipBits(program_info_length * 8); // skip descriptors 176 177 // infoBytesRemaining is the number of bytes that make up the 178 // variable length section of ES_infos. It does not include the 179 // final CRC. 180 size_t infoBytesRemaining = section_length - 9 - program_info_length - 4; 181 182 while (infoBytesRemaining > 0) { 183 CHECK_GE(infoBytesRemaining, 5u); 184 185 unsigned streamType = br->getBits(8); 186 LOGV(" stream_type = 0x%02x", streamType); 187 188 MY_LOGV(" reserved = %u", br->getBits(3)); 189 190 unsigned elementaryPID = br->getBits(13); 191 LOGV(" elementary_PID = 0x%04x", elementaryPID); 192 193 MY_LOGV(" reserved = %u", br->getBits(4)); 194 195 unsigned ES_info_length = br->getBits(12); 196 LOGV(" ES_info_length = %u", ES_info_length); 197 CHECK((ES_info_length & 0xc00) == 0); 198 199 CHECK_GE(infoBytesRemaining - 5, ES_info_length); 200 201#if 0 202 br->skipBits(ES_info_length * 8); // skip descriptors 203#else 204 unsigned info_bytes_remaining = ES_info_length; 205 while (info_bytes_remaining >= 2) { 206 MY_LOGV(" tag = 0x%02x", br->getBits(8)); 207 208 unsigned descLength = br->getBits(8); 209 LOGV(" len = %u", descLength); 210 211 CHECK_GE(info_bytes_remaining, 2 + descLength); 212 213 br->skipBits(descLength * 8); 214 215 info_bytes_remaining -= descLength + 2; 216 } 217 CHECK_EQ(info_bytes_remaining, 0u); 218#endif 219 220 ssize_t index = mStreams.indexOfKey(elementaryPID); 221#if 0 // XXX revisit 222 CHECK_LT(index, 0); 223 mStreams.add(elementaryPID, 224 new Stream(this, elementaryPID, streamType)); 225#else 226 if (index < 0) { 227 mStreams.add(elementaryPID, 228 new Stream(this, elementaryPID, streamType)); 229 } 230#endif 231 232 infoBytesRemaining -= 5 + ES_info_length; 233 } 234 235 CHECK_EQ(infoBytesRemaining, 0u); 236 237 MY_LOGV(" CRC = 0x%08x", br->getBits(32)); 238} 239 240sp<MediaSource> ATSParser::Program::getSource(SourceType type) { 241 size_t index = (type == MPEG2ADTS_AUDIO) ? 0 : 0; 242 243 for (size_t i = 0; i < mStreams.size(); ++i) { 244 sp<MediaSource> source = mStreams.editValueAt(i)->getSource(type); 245 if (source != NULL) { 246 if (index == 0) { 247 return source; 248 } 249 --index; 250 } 251 } 252 253 return NULL; 254} 255 256int64_t ATSParser::Program::convertPTSToTimestamp(uint64_t PTS) { 257 if (!mFirstPTSValid) { 258 mFirstPTSValid = true; 259 mFirstPTS = PTS; 260 PTS = 0; 261 } else if (PTS < mFirstPTS) { 262 PTS = 0; 263 } else { 264 PTS -= mFirstPTS; 265 } 266 267 return (PTS * 100) / 9; 268} 269 270//////////////////////////////////////////////////////////////////////////////// 271 272ATSParser::Stream::Stream( 273 Program *program, unsigned elementaryPID, unsigned streamType) 274 : mProgram(program), 275 mElementaryPID(elementaryPID), 276 mStreamType(streamType), 277 mBuffer(new ABuffer(128 * 1024)), 278 mPayloadStarted(false), 279 mQueue(streamType == 0x1b 280 ? ElementaryStreamQueue::H264 : ElementaryStreamQueue::AAC) { 281 mBuffer->setRange(0, 0); 282 283 LOGV("new stream PID 0x%02x, type 0x%02x", elementaryPID, streamType); 284} 285 286ATSParser::Stream::~Stream() { 287} 288 289void ATSParser::Stream::parse( 290 unsigned payload_unit_start_indicator, ABitReader *br) { 291 if (payload_unit_start_indicator) { 292 if (mPayloadStarted) { 293 // Otherwise we run the danger of receiving the trailing bytes 294 // of a PES packet that we never saw the start of and assuming 295 // we have a a complete PES packet. 296 297 flush(); 298 } 299 300 mPayloadStarted = true; 301 } 302 303 if (!mPayloadStarted) { 304 return; 305 } 306 307 size_t payloadSizeBits = br->numBitsLeft(); 308 CHECK((payloadSizeBits % 8) == 0); 309 310 CHECK_LE(mBuffer->size() + payloadSizeBits / 8, mBuffer->capacity()); 311 312 memcpy(mBuffer->data() + mBuffer->size(), br->data(), payloadSizeBits / 8); 313 mBuffer->setRange(0, mBuffer->size() + payloadSizeBits / 8); 314} 315 316void ATSParser::Stream::signalDiscontinuity(bool isASeek) { 317 isASeek = false; // Always signal a "real" discontinuity 318 319 mPayloadStarted = false; 320 mBuffer->setRange(0, 0); 321 322 mQueue.clear(); 323 324 if (isASeek) { 325 // This is only a "minor" discontinuity, we stay within the same 326 // bitstream. 327 328 if (mSource != NULL) { 329 mSource->clear(); 330 } 331 return; 332 } 333 334 if (mStreamType == 0x1b && mSource != NULL) { 335 // Don't signal discontinuities on audio streams. 336 mSource->queueDiscontinuity(); 337 } 338} 339 340void ATSParser::Stream::parsePES(ABitReader *br) { 341 unsigned packet_startcode_prefix = br->getBits(24); 342 343 LOGV("packet_startcode_prefix = 0x%08x", packet_startcode_prefix); 344 345 CHECK_EQ(packet_startcode_prefix, 0x000001u); 346 347 unsigned stream_id = br->getBits(8); 348 LOGV("stream_id = 0x%02x", stream_id); 349 350 unsigned PES_packet_length = br->getBits(16); 351 LOGV("PES_packet_length = %u", PES_packet_length); 352 353 if (stream_id != 0xbc // program_stream_map 354 && stream_id != 0xbe // padding_stream 355 && stream_id != 0xbf // private_stream_2 356 && stream_id != 0xf0 // ECM 357 && stream_id != 0xf1 // EMM 358 && stream_id != 0xff // program_stream_directory 359 && stream_id != 0xf2 // DSMCC 360 && stream_id != 0xf8) { // H.222.1 type E 361 CHECK_EQ(br->getBits(2), 2u); 362 363 MY_LOGV("PES_scrambling_control = %u", br->getBits(2)); 364 MY_LOGV("PES_priority = %u", br->getBits(1)); 365 MY_LOGV("data_alignment_indicator = %u", br->getBits(1)); 366 MY_LOGV("copyright = %u", br->getBits(1)); 367 MY_LOGV("original_or_copy = %u", br->getBits(1)); 368 369 unsigned PTS_DTS_flags = br->getBits(2); 370 LOGV("PTS_DTS_flags = %u", PTS_DTS_flags); 371 372 unsigned ESCR_flag = br->getBits(1); 373 LOGV("ESCR_flag = %u", ESCR_flag); 374 375 unsigned ES_rate_flag = br->getBits(1); 376 LOGV("ES_rate_flag = %u", ES_rate_flag); 377 378 unsigned DSM_trick_mode_flag = br->getBits(1); 379 LOGV("DSM_trick_mode_flag = %u", DSM_trick_mode_flag); 380 381 unsigned additional_copy_info_flag = br->getBits(1); 382 LOGV("additional_copy_info_flag = %u", additional_copy_info_flag); 383 384 MY_LOGV("PES_CRC_flag = %u", br->getBits(1)); 385 MY_LOGV("PES_extension_flag = %u", br->getBits(1)); 386 387 unsigned PES_header_data_length = br->getBits(8); 388 LOGV("PES_header_data_length = %u", PES_header_data_length); 389 390 unsigned optional_bytes_remaining = PES_header_data_length; 391 392 uint64_t PTS = 0, DTS = 0; 393 394 if (PTS_DTS_flags == 2 || PTS_DTS_flags == 3) { 395 CHECK_GE(optional_bytes_remaining, 5u); 396 397 CHECK_EQ(br->getBits(4), PTS_DTS_flags); 398 399 PTS = ((uint64_t)br->getBits(3)) << 30; 400 CHECK_EQ(br->getBits(1), 1u); 401 PTS |= ((uint64_t)br->getBits(15)) << 15; 402 CHECK_EQ(br->getBits(1), 1u); 403 PTS |= br->getBits(15); 404 CHECK_EQ(br->getBits(1), 1u); 405 406 LOGV("PTS = %llu", PTS); 407 // LOGI("PTS = %.2f secs", PTS / 90000.0f); 408 409 optional_bytes_remaining -= 5; 410 411 if (PTS_DTS_flags == 3) { 412 CHECK_GE(optional_bytes_remaining, 5u); 413 414 CHECK_EQ(br->getBits(4), 1u); 415 416 DTS = ((uint64_t)br->getBits(3)) << 30; 417 CHECK_EQ(br->getBits(1), 1u); 418 DTS |= ((uint64_t)br->getBits(15)) << 15; 419 CHECK_EQ(br->getBits(1), 1u); 420 DTS |= br->getBits(15); 421 CHECK_EQ(br->getBits(1), 1u); 422 423 LOGV("DTS = %llu", DTS); 424 425 optional_bytes_remaining -= 5; 426 } 427 } 428 429 if (ESCR_flag) { 430 CHECK_GE(optional_bytes_remaining, 6u); 431 432 br->getBits(2); 433 434 uint64_t ESCR = ((uint64_t)br->getBits(3)) << 30; 435 CHECK_EQ(br->getBits(1), 1u); 436 ESCR |= ((uint64_t)br->getBits(15)) << 15; 437 CHECK_EQ(br->getBits(1), 1u); 438 ESCR |= br->getBits(15); 439 CHECK_EQ(br->getBits(1), 1u); 440 441 LOGV("ESCR = %llu", ESCR); 442 MY_LOGV("ESCR_extension = %u", br->getBits(9)); 443 444 CHECK_EQ(br->getBits(1), 1u); 445 446 optional_bytes_remaining -= 6; 447 } 448 449 if (ES_rate_flag) { 450 CHECK_GE(optional_bytes_remaining, 3u); 451 452 CHECK_EQ(br->getBits(1), 1u); 453 MY_LOGV("ES_rate = %u", br->getBits(22)); 454 CHECK_EQ(br->getBits(1), 1u); 455 456 optional_bytes_remaining -= 3; 457 } 458 459 br->skipBits(optional_bytes_remaining * 8); 460 461 // ES data follows. 462 463 if (PES_packet_length != 0) { 464 CHECK_GE(PES_packet_length, PES_header_data_length + 3); 465 466 unsigned dataLength = 467 PES_packet_length - 3 - PES_header_data_length; 468 469 CHECK_GE(br->numBitsLeft(), dataLength * 8); 470 471 onPayloadData( 472 PTS_DTS_flags, PTS, DTS, br->data(), dataLength); 473 474 br->skipBits(dataLength * 8); 475 } else { 476 onPayloadData( 477 PTS_DTS_flags, PTS, DTS, 478 br->data(), br->numBitsLeft() / 8); 479 480 size_t payloadSizeBits = br->numBitsLeft(); 481 CHECK((payloadSizeBits % 8) == 0); 482 483 LOGV("There's %d bytes of payload.", payloadSizeBits / 8); 484 } 485 } else if (stream_id == 0xbe) { // padding_stream 486 CHECK_NE(PES_packet_length, 0u); 487 br->skipBits(PES_packet_length * 8); 488 } else { 489 CHECK_NE(PES_packet_length, 0u); 490 br->skipBits(PES_packet_length * 8); 491 } 492} 493 494void ATSParser::Stream::flush() { 495 if (mBuffer->size() == 0) { 496 return; 497 } 498 499 LOGV("flushing stream 0x%04x size = %d", mElementaryPID, mBuffer->size()); 500 501 ABitReader br(mBuffer->data(), mBuffer->size()); 502 parsePES(&br); 503 504 mBuffer->setRange(0, 0); 505} 506 507void ATSParser::Stream::onPayloadData( 508 unsigned PTS_DTS_flags, uint64_t PTS, uint64_t DTS, 509 const uint8_t *data, size_t size) { 510 LOGV("onPayloadData mStreamType=0x%02x", mStreamType); 511 512 CHECK(PTS_DTS_flags == 2 || PTS_DTS_flags == 3); 513 int64_t timeUs = mProgram->convertPTSToTimestamp(PTS); 514 515 status_t err = mQueue.appendData(data, size, timeUs); 516 517 if (err != OK) { 518 return; 519 } 520 521 sp<ABuffer> accessUnit; 522 while ((accessUnit = mQueue.dequeueAccessUnit()) != NULL) { 523 if (mSource == NULL) { 524 sp<MetaData> meta = mQueue.getFormat(); 525 526 if (meta != NULL) { 527 LOGV("created source!"); 528 mSource = new AnotherPacketSource(meta); 529 mSource->queueAccessUnit(accessUnit); 530 } 531 } else if (mQueue.getFormat() != NULL) { 532 // After a discontinuity we invalidate the queue's format 533 // and won't enqueue any access units to the source until 534 // the queue has reestablished the new format. 535 mSource->queueAccessUnit(accessUnit); 536 } 537 } 538} 539 540sp<MediaSource> ATSParser::Stream::getSource(SourceType type) { 541 if ((type == AVC_VIDEO && mStreamType == 0x1b) 542 || (type == MPEG2ADTS_AUDIO && mStreamType == 0x0f)) { 543 return mSource; 544 } 545 546 return NULL; 547} 548 549//////////////////////////////////////////////////////////////////////////////// 550 551ATSParser::ATSParser() { 552} 553 554ATSParser::~ATSParser() { 555} 556 557void ATSParser::feedTSPacket(const void *data, size_t size) { 558 CHECK_EQ(size, kTSPacketSize); 559 560 ABitReader br((const uint8_t *)data, kTSPacketSize); 561 parseTS(&br); 562} 563 564void ATSParser::signalDiscontinuity(bool isASeek) { 565 for (size_t i = 0; i < mPrograms.size(); ++i) { 566 mPrograms.editItemAt(i)->signalDiscontinuity(isASeek); 567 } 568} 569 570void ATSParser::parseProgramAssociationTable(ABitReader *br) { 571 unsigned table_id = br->getBits(8); 572 LOGV(" table_id = %u", table_id); 573 CHECK_EQ(table_id, 0x00u); 574 575 unsigned section_syntax_indictor = br->getBits(1); 576 LOGV(" section_syntax_indictor = %u", section_syntax_indictor); 577 CHECK_EQ(section_syntax_indictor, 1u); 578 579 CHECK_EQ(br->getBits(1), 0u); 580 MY_LOGV(" reserved = %u", br->getBits(2)); 581 582 unsigned section_length = br->getBits(12); 583 LOGV(" section_length = %u", section_length); 584 CHECK((section_length & 0xc00) == 0); 585 586 MY_LOGV(" transport_stream_id = %u", br->getBits(16)); 587 MY_LOGV(" reserved = %u", br->getBits(2)); 588 MY_LOGV(" version_number = %u", br->getBits(5)); 589 MY_LOGV(" current_next_indicator = %u", br->getBits(1)); 590 MY_LOGV(" section_number = %u", br->getBits(8)); 591 MY_LOGV(" last_section_number = %u", br->getBits(8)); 592 593 size_t numProgramBytes = (section_length - 5 /* header */ - 4 /* crc */); 594 CHECK_EQ((numProgramBytes % 4), 0u); 595 596 for (size_t i = 0; i < numProgramBytes / 4; ++i) { 597 unsigned program_number = br->getBits(16); 598 LOGV(" program_number = %u", program_number); 599 600 MY_LOGV(" reserved = %u", br->getBits(3)); 601 602 if (program_number == 0) { 603 MY_LOGV(" network_PID = 0x%04x", br->getBits(13)); 604 } else { 605 unsigned programMapPID = br->getBits(13); 606 607 LOGV(" program_map_PID = 0x%04x", programMapPID); 608 609 mPrograms.push(new Program(programMapPID)); 610 } 611 } 612 613 MY_LOGV(" CRC = 0x%08x", br->getBits(32)); 614} 615 616void ATSParser::parsePID( 617 ABitReader *br, unsigned PID, 618 unsigned payload_unit_start_indicator) { 619 if (PID == 0) { 620 if (payload_unit_start_indicator) { 621 unsigned skip = br->getBits(8); 622 br->skipBits(skip * 8); 623 } 624 parseProgramAssociationTable(br); 625 return; 626 } 627 628 bool handled = false; 629 for (size_t i = 0; i < mPrograms.size(); ++i) { 630 if (mPrograms.editItemAt(i)->parsePID( 631 PID, payload_unit_start_indicator, br)) { 632 handled = true; 633 break; 634 } 635 } 636 637 if (!handled) { 638 LOGV("PID 0x%04x not handled.", PID); 639 } 640} 641 642void ATSParser::parseAdaptationField(ABitReader *br) { 643 unsigned adaptation_field_length = br->getBits(8); 644 if (adaptation_field_length > 0) { 645 br->skipBits(adaptation_field_length * 8); // XXX 646 } 647} 648 649void ATSParser::parseTS(ABitReader *br) { 650 LOGV("---"); 651 652 unsigned sync_byte = br->getBits(8); 653 CHECK_EQ(sync_byte, 0x47u); 654 655 MY_LOGV("transport_error_indicator = %u", br->getBits(1)); 656 657 unsigned payload_unit_start_indicator = br->getBits(1); 658 LOGV("payload_unit_start_indicator = %u", payload_unit_start_indicator); 659 660 MY_LOGV("transport_priority = %u", br->getBits(1)); 661 662 unsigned PID = br->getBits(13); 663 LOGV("PID = 0x%04x", PID); 664 665 MY_LOGV("transport_scrambling_control = %u", br->getBits(2)); 666 667 unsigned adaptation_field_control = br->getBits(2); 668 LOGV("adaptation_field_control = %u", adaptation_field_control); 669 670 unsigned continuity_counter = br->getBits(4); 671 LOGV("continuity_counter = %u", continuity_counter); 672 673 // LOGI("PID = 0x%04x, continuity_counter = %u", PID, continuity_counter); 674 675 if (adaptation_field_control == 2 || adaptation_field_control == 3) { 676 parseAdaptationField(br); 677 } 678 679 if (adaptation_field_control == 1 || adaptation_field_control == 3) { 680 parsePID(br, PID, payload_unit_start_indicator); 681 } 682} 683 684sp<MediaSource> ATSParser::getSource(SourceType type) { 685 for (size_t i = 0; i < mPrograms.size(); ++i) { 686 sp<MediaSource> source = mPrograms.editItemAt(i)->getSource(type); 687 688 if (source != NULL) { 689 return source; 690 } 691 } 692 693 return NULL; 694} 695 696} // namespace android 697