OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
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 are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultH264PlType, | 337 codecs.push_back(MakeVideoCodecWithDefaultFeedbackParams(kDefaultH264PlType, |
338 kH264CodecName)); | 338 kH264CodecName)); |
339 } | 339 } |
340 codecs.push_back( | 340 codecs.push_back( |
341 VideoCodec::CreateRtxCodec(kDefaultRtxVp8PlType, kDefaultVp8PlType)); | 341 VideoCodec::CreateRtxCodec(kDefaultRtxVp8PlType, kDefaultVp8PlType)); |
342 codecs.push_back(VideoCodec(kDefaultRedPlType, kRedCodecName)); | 342 codecs.push_back(VideoCodec(kDefaultRedPlType, kRedCodecName)); |
343 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); | 343 codecs.push_back(VideoCodec(kDefaultUlpfecType, kUlpfecCodecName)); |
344 return codecs; | 344 return codecs; |
345 } | 345 } |
346 | 346 |
347 static bool FindFirstMatchingCodec(const std::vector<VideoCodec>& codecs, | |
348 const VideoCodec& requested_codec, | |
349 VideoCodec* matching_codec) { | |
350 for (size_t i = 0; i < codecs.size(); ++i) { | |
351 if (requested_codec.Matches(codecs[i])) { | |
352 *matching_codec = codecs[i]; | |
353 return true; | |
354 } | |
355 } | |
356 return false; | |
357 } | |
358 | |
359 std::vector<webrtc::VideoStream> | 347 std::vector<webrtc::VideoStream> |
360 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( | 348 WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( |
361 const VideoCodec& codec, | 349 const VideoCodec& codec, |
362 const VideoOptions& options, | 350 const VideoOptions& options, |
363 int max_bitrate_bps, | 351 int max_bitrate_bps, |
364 size_t num_streams) { | 352 size_t num_streams) { |
365 int max_qp = kDefaultQpMax; | 353 int max_qp = kDefaultQpMax; |
366 codec.GetParam(kCodecParamMaxQuantization, &max_qp); | 354 codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
367 | 355 |
368 return GetSimulcastConfig( | 356 return GetSimulcastConfig( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 480 |
493 WebRtcVideoEngine2::~WebRtcVideoEngine2() { | 481 WebRtcVideoEngine2::~WebRtcVideoEngine2() { |
494 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; | 482 LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; |
495 } | 483 } |
496 | 484 |
497 void WebRtcVideoEngine2::Init() { | 485 void WebRtcVideoEngine2::Init() { |
498 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; | 486 LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; |
499 initialized_ = true; | 487 initialized_ = true; |
500 } | 488 } |
501 | 489 |
502 bool WebRtcVideoEngine2::SetDefaultEncoderConfig( | |
503 const VideoEncoderConfig& config) { | |
504 const VideoCodec& codec = config.max_codec; | |
505 bool supports_codec = false; | |
506 for (size_t i = 0; i < video_codecs_.size(); ++i) { | |
507 if (CodecNamesEq(video_codecs_[i].name, codec.name)) { | |
508 video_codecs_[i].width = codec.width; | |
509 video_codecs_[i].height = codec.height; | |
510 video_codecs_[i].framerate = codec.framerate; | |
511 supports_codec = true; | |
512 break; | |
513 } | |
514 } | |
515 | |
516 if (!supports_codec) { | |
517 LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " | |
518 << codec.ToString(); | |
519 return false; | |
520 } | |
521 | |
522 return true; | |
523 } | |
524 | |
525 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( | 490 WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( |
526 webrtc::Call* call, | 491 webrtc::Call* call, |
527 const VideoOptions& options) { | 492 const VideoOptions& options) { |
528 RTC_DCHECK(initialized_); | 493 RTC_DCHECK(initialized_); |
529 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); | 494 LOG(LS_INFO) << "CreateChannel. Options: " << options.ToString(); |
530 return new WebRtcVideoChannel2(call, options, video_codecs_, | 495 return new WebRtcVideoChannel2(call, options, video_codecs_, |
531 external_encoder_factory_, external_decoder_factory_); | 496 external_encoder_factory_, external_decoder_factory_); |
532 } | 497 } |
533 | 498 |
534 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { | 499 const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 // with this code (that doesn't ask the factory). | 559 // with this code (that doesn't ask the factory). |
595 for (size_t j = 0; j < video_codecs_.size(); ++j) { | 560 for (size_t j = 0; j < video_codecs_.size(); ++j) { |
596 VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0); | 561 VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0); |
597 if (codec.Matches(in)) { | 562 if (codec.Matches(in)) { |
598 return true; | 563 return true; |
599 } | 564 } |
600 } | 565 } |
601 return false; | 566 return false; |
602 } | 567 } |
603 | 568 |
604 // Tells whether the |requested| codec can be transmitted or not. If it can be | |
605 // transmitted |out| is set with the best settings supported. Aspect ratio will | |
606 // be set as close to |current|'s as possible. If not set |requested|'s | |
607 // dimensions will be used for aspect ratio matching. | |
608 bool WebRtcVideoEngine2::CanSendCodec(const VideoCodec& requested, | |
609 const VideoCodec& current, | |
610 VideoCodec* out) { | |
611 RTC_DCHECK(out != NULL); | |
612 | |
613 if (requested.width != requested.height && | |
614 (requested.height == 0 || requested.width == 0)) { | |
615 // 0xn and nx0 are invalid resolutions. | |
616 return false; | |
617 } | |
618 | |
619 VideoCodec matching_codec; | |
620 if (!FindFirstMatchingCodec(video_codecs_, requested, &matching_codec)) { | |
621 // Codec not supported. | |
622 return false; | |
623 } | |
624 | |
625 out->id = requested.id; | |
626 out->name = requested.name; | |
627 out->preference = requested.preference; | |
628 out->params = requested.params; | |
629 out->framerate = std::min(requested.framerate, matching_codec.framerate); | |
630 out->params = requested.params; | |
631 out->feedback_params = requested.feedback_params; | |
632 out->width = requested.width; | |
633 out->height = requested.height; | |
634 if (requested.width == 0 && requested.height == 0) { | |
635 return true; | |
636 } | |
637 | |
638 while (out->width > matching_codec.width) { | |
639 out->width /= 2; | |
640 out->height /= 2; | |
641 } | |
642 | |
643 return out->width > 0 && out->height > 0; | |
644 } | |
645 | |
646 // Ignore spammy trace messages, mostly from the stats API when we haven't | 569 // Ignore spammy trace messages, mostly from the stats API when we haven't |
647 // gotten RTCP info yet from the remote side. | 570 // gotten RTCP info yet from the remote side. |
648 bool WebRtcVideoEngine2::ShouldIgnoreTrace(const std::string& trace) { | 571 bool WebRtcVideoEngine2::ShouldIgnoreTrace(const std::string& trace) { |
649 static const char* const kTracesToIgnore[] = {NULL}; | 572 static const char* const kTracesToIgnore[] = {NULL}; |
650 for (const char* const* p = kTracesToIgnore; *p; ++p) { | 573 for (const char* const* p = kTracesToIgnore; *p; ++p) { |
651 if (trace.find(*p) == 0) { | 574 if (trace.find(*p) == 0) { |
652 return true; | 575 return true; |
653 } | 576 } |
654 } | 577 } |
655 return false; | 578 return false; |
(...skipping 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2730 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; | 2653 video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
2731 } | 2654 } |
2732 } | 2655 } |
2733 | 2656 |
2734 return video_codecs; | 2657 return video_codecs; |
2735 } | 2658 } |
2736 | 2659 |
2737 } // namespace cricket | 2660 } // namespace cricket |
2738 | 2661 |
2739 #endif // HAVE_WEBRTC_VIDEO | 2662 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |