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

Side by Side Diff: third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp

Issue 1977513004: Adds multiple forms of MediaStreamTrack constraints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Tommi's comments Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 Vector<NameValueStringConstraint> optional; 446 Vector<NameValueStringConstraint> optional;
447 Vector<NameValueStringConstraint> mandatory; 447 Vector<NameValueStringConstraint> mandatory;
448 if (!parse(constraintsDictionary, optional, mandatory)) { 448 if (!parse(constraintsDictionary, optional, mandatory)) {
449 errorState.throwTypeError("Malformed constraints object."); 449 errorState.throwTypeError("Malformed constraints object.");
450 return WebMediaConstraints(); 450 return WebMediaConstraints();
451 } 451 }
452 UseCounter::count(context, UseCounter::MediaStreamConstraintsFromDictionary) ; 452 UseCounter::count(context, UseCounter::MediaStreamConstraintsFromDictionary) ;
453 return createFromNamedConstraints(context, mandatory, optional, errorState); 453 return createFromNamedConstraints(context, mandatory, optional, errorState);
454 } 454 }
455 455
456 void copyLongConstraint(const ConstrainLongRange& blinkForm, LongConstraint& web Form) 456 void copyLongConstraint(const LongOrConstrainLongRange& blinkUnionForm, LongCons traint& webForm)
457 { 457 {
458 if (blinkUnionForm.isLong()) {
459 webForm.setIdeal(blinkUnionForm.getAsLong());
460 return;
461 }
462 const auto& blinkForm = blinkUnionForm.getAsConstrainLongRange();
458 if (blinkForm.hasMin()) { 463 if (blinkForm.hasMin()) {
459 webForm.setMin(blinkForm.min()); 464 webForm.setMin(blinkForm.min());
460 } 465 }
461 if (blinkForm.hasMax()) { 466 if (blinkForm.hasMax()) {
462 webForm.setMax(blinkForm.max()); 467 webForm.setMax(blinkForm.max());
463 } 468 }
464 if (blinkForm.hasIdeal()) { 469 if (blinkForm.hasIdeal()) {
465 webForm.setIdeal(blinkForm.ideal()); 470 webForm.setIdeal(blinkForm.ideal());
466 } 471 }
467 if (blinkForm.hasExact()) { 472 if (blinkForm.hasExact()) {
468 webForm.setExact(blinkForm.exact()); 473 webForm.setExact(blinkForm.exact());
469 } 474 }
470 } 475 }
471 476
472 void copyDoubleConstraint(const ConstrainDoubleRange& blinkForm, DoubleConstrain t& webForm) 477 void copyDoubleConstraint(const DoubleOrConstrainDoubleRange& blinkUnionForm, Do ubleConstraint& webForm)
473 { 478 {
479 if (blinkUnionForm.isDouble()) {
480 webForm.setIdeal(blinkUnionForm.getAsDouble());
481 return;
482 }
483 const auto& blinkForm = blinkUnionForm.getAsConstrainDoubleRange();
474 if (blinkForm.hasMin()) { 484 if (blinkForm.hasMin()) {
475 webForm.setMin(blinkForm.min()); 485 webForm.setMin(blinkForm.min());
476 } 486 }
477 if (blinkForm.hasMax()) { 487 if (blinkForm.hasMax()) {
478 webForm.setMax(blinkForm.max()); 488 webForm.setMax(blinkForm.max());
479 } 489 }
480 if (blinkForm.hasIdeal()) { 490 if (blinkForm.hasIdeal()) {
481 webForm.setIdeal(blinkForm.ideal()); 491 webForm.setIdeal(blinkForm.ideal());
482 } 492 }
483 if (blinkForm.hasExact()) { 493 if (blinkForm.hasExact()) {
484 webForm.setExact(blinkForm.exact()); 494 webForm.setExact(blinkForm.exact());
485 } 495 }
486 } 496 }
487 497
488 void copyStringConstraint(const ConstrainDOMStringParameters& blinkForm, StringC onstraint& webForm) 498 void copyStringConstraint(const StringOrStringSequenceOrConstrainDOMStringParame ters& blinkUnionForm, StringConstraint& webForm)
489 { 499 {
500 if (blinkUnionForm.isString()) {
501 webForm.setIdeal(Vector<String>(1, blinkUnionForm.getAsString()));
502 return;
503 }
504 if (blinkUnionForm.isStringSequence()) {
505 webForm.setIdeal(blinkUnionForm.getAsStringSequence());
506 return;
507 }
508 const auto& blinkForm = blinkUnionForm.getAsConstrainDOMStringParameters();
490 if (blinkForm.hasIdeal()) { 509 if (blinkForm.hasIdeal()) {
491 webForm.setIdeal(WebVector<WebString>(blinkForm.ideal())); 510 if (blinkForm.ideal().isStringSequence()) {
511 webForm.setIdeal(blinkForm.ideal().getAsStringSequence());
512 } else if (blinkForm.ideal().isString()) {
513 webForm.setIdeal(Vector<String>(1, blinkForm.ideal().getAsString())) ;
514 }
492 } 515 }
493 if (blinkForm.hasExact()) { 516 if (blinkForm.hasExact()) {
494 webForm.setExact(WebVector<WebString>(blinkForm.exact())); 517 if (blinkForm.exact().isStringSequence()) {
518 webForm.setExact(blinkForm.exact().getAsStringSequence());
519 } else if (blinkForm.exact().isString()) {
520 webForm.setExact(Vector<String>(1, blinkForm.exact().getAsString())) ;
521 }
495 } 522 }
496 } 523 }
497 524
498 void copyBooleanConstraint(const ConstrainBooleanParameters& blinkForm, BooleanC onstraint& webForm) 525 void copyBooleanConstraint(const BooleanOrConstrainBooleanParameters& blinkUnion Form, BooleanConstraint& webForm)
499 { 526 {
527 if (blinkUnionForm.isBoolean()) {
528 webForm.setIdeal(blinkUnionForm.getAsBoolean());
529 return;
530 }
531 const auto& blinkForm = blinkUnionForm.getAsConstrainBooleanParameters();
500 if (blinkForm.hasIdeal()) { 532 if (blinkForm.hasIdeal()) {
501 webForm.setIdeal(blinkForm.ideal()); 533 webForm.setIdeal(blinkForm.ideal());
502 } 534 }
503 if (blinkForm.hasExact()) { 535 if (blinkForm.hasExact()) {
504 webForm.setExact(blinkForm.exact()); 536 webForm.setExact(blinkForm.exact());
505 } 537 }
506 } 538 }
507 539
508 void copyConstraints(const MediaTrackConstraintSet& constraintsIn, WebMediaTrack ConstraintSet& constraintBuffer) 540 void copyConstraintSet(const MediaTrackConstraintSet& constraintsIn, WebMediaTra ckConstraintSet& constraintBuffer)
509 { 541 {
510 if (constraintsIn.hasWidth()) { 542 if (constraintsIn.hasWidth()) {
511 copyLongConstraint(constraintsIn.width(), constraintBuffer.width); 543 copyLongConstraint(constraintsIn.width(), constraintBuffer.width);
512 } 544 }
513 if (constraintsIn.hasHeight()) { 545 if (constraintsIn.hasHeight()) {
514 copyLongConstraint(constraintsIn.height(), constraintBuffer.height); 546 copyLongConstraint(constraintsIn.height(), constraintBuffer.height);
515 } 547 }
516 if (constraintsIn.hasAspectRatio()) { 548 if (constraintsIn.hasAspectRatio()) {
517 copyDoubleConstraint(constraintsIn.aspectRatio(), constraintBuffer.aspec tRatio); 549 copyDoubleConstraint(constraintsIn.aspectRatio(), constraintBuffer.aspec tRatio);
518 } 550 }
(...skipping 22 matching lines...) Expand all
541 copyLongConstraint(constraintsIn.channelCount(), constraintBuffer.channe lCount); 573 copyLongConstraint(constraintsIn.channelCount(), constraintBuffer.channe lCount);
542 } 574 }
543 if (constraintsIn.hasDeviceId()) { 575 if (constraintsIn.hasDeviceId()) {
544 copyStringConstraint(constraintsIn.deviceId(), constraintBuffer.deviceId ); 576 copyStringConstraint(constraintsIn.deviceId(), constraintBuffer.deviceId );
545 } 577 }
546 if (constraintsIn.hasGroupId()) { 578 if (constraintsIn.hasGroupId()) {
547 copyStringConstraint(constraintsIn.groupId(), constraintBuffer.groupId); 579 copyStringConstraint(constraintsIn.groupId(), constraintBuffer.groupId);
548 } 580 }
549 } 581 }
550 582
583 WebMediaConstraints convertConstraintsToWeb(const MediaTrackConstraints& constra intsIn)
584 {
585 WebMediaConstraints constraints;
586 WebMediaTrackConstraintSet constraintBuffer;
587 Vector<WebMediaTrackConstraintSet> advancedBuffer;
588 copyConstraintSet(constraintsIn, constraintBuffer);
589 if (constraintsIn.hasAdvanced()) {
590 for (const auto& element : constraintsIn.advanced()) {
591 WebMediaTrackConstraintSet advancedElement;
592 copyConstraintSet(element, advancedElement);
593 advancedBuffer.append(advancedElement);
594 }
595 }
596 constraints.initialize(constraintBuffer, advancedBuffer);
597 return constraints;
598 }
599
551 WebMediaConstraints create(ExecutionContext* context, const MediaTrackConstraint s& constraintsIn, MediaErrorState& errorState) 600 WebMediaConstraints create(ExecutionContext* context, const MediaTrackConstraint s& constraintsIn, MediaErrorState& errorState)
552 { 601 {
553 WebMediaConstraints constraints; 602 WebMediaConstraints standardForm = convertConstraintsToWeb(constraintsIn);
554 WebMediaTrackConstraintSet constraintBuffer;
555 Vector<WebMediaTrackConstraintSet> advancedBuffer;
556 copyConstraints(constraintsIn, constraintBuffer);
557 if (constraintsIn.hasAdvanced()) {
558 for (const auto& element : constraintsIn.advanced()) {
559 WebMediaTrackConstraintSet advancedElement;
560 copyConstraints(element, advancedElement);
561 advancedBuffer.append(advancedElement);
562 }
563 }
564 // TODO(hta): Add initialization of advanced constraints once present.
565 // https://crbug.com/253412
566 if (constraintsIn.hasOptional() || constraintsIn.hasMandatory()) { 603 if (constraintsIn.hasOptional() || constraintsIn.hasMandatory()) {
567 if (!constraintBuffer.isEmpty() || constraintsIn.hasAdvanced()) { 604 if (!standardForm.isEmpty()) {
568 errorState.throwTypeError("Malformed constraint: Cannot use both opt ional/mandatory and specific or advanced constraints."); 605 errorState.throwTypeError("Malformed constraint: Cannot use both opt ional/mandatory and specific or advanced constraints.");
569 return WebMediaConstraints(); 606 return WebMediaConstraints();
570 } 607 }
571 Vector<NameValueStringConstraint> optional; 608 Vector<NameValueStringConstraint> optional;
572 Vector<NameValueStringConstraint> mandatory; 609 Vector<NameValueStringConstraint> mandatory;
573 if (!parse(constraintsIn, optional, mandatory)) { 610 if (!parse(constraintsIn, optional, mandatory)) {
574 errorState.throwTypeError("Malformed constraints object."); 611 errorState.throwTypeError("Malformed constraints object.");
575 return WebMediaConstraints(); 612 return WebMediaConstraints();
576 } 613 }
577 UseCounter::count(context, UseCounter::MediaStreamConstraintsNameValue); 614 UseCounter::count(context, UseCounter::MediaStreamConstraintsNameValue);
578 return createFromNamedConstraints(context, mandatory, optional, errorSta te); 615 return createFromNamedConstraints(context, mandatory, optional, errorSta te);
579 } 616 }
580 UseCounter::count(context, UseCounter::MediaStreamConstraintsConformant); 617 UseCounter::count(context, UseCounter::MediaStreamConstraintsConformant);
581 constraints.initialize(constraintBuffer, advancedBuffer); 618 return standardForm;
582 return constraints;
583 } 619 }
584 620
585 WebMediaConstraints create() 621 WebMediaConstraints create()
586 { 622 {
587 WebMediaConstraints constraints; 623 WebMediaConstraints constraints;
588 constraints.initialize(); 624 constraints.initialize();
589 return constraints; 625 return constraints;
590 } 626 }
591 627
592 ConstrainLongRange convertLong(const LongConstraint& input) 628 LongOrConstrainLongRange convertLong(const LongConstraint& input)
593 { 629 {
594 630 LongOrConstrainLongRange outputUnion;
595 ConstrainLongRange output; 631 if (input.hasExact() || input.hasMin() || input.hasMax()) {
596 if (input.hasExact()) 632 ConstrainLongRange output;
597 output.setExact(input.exact()); 633 if (input.hasExact())
598 if (input.hasIdeal()) 634 output.setExact(input.exact());
599 output.setIdeal(input.ideal()); 635 if (input.hasMin())
600 if (input.hasMin()) 636 output.setMin(input.min());
601 output.setMin(input.min()); 637 if (input.hasMax())
602 if (input.hasMax()) 638 output.setMax(input.max());
603 output.setMax(input.max()); 639 if (input.hasIdeal())
604 return output; 640 output.setIdeal(input.ideal());
641 outputUnion.setConstrainLongRange(output);
642 } else {
643 if (input.hasIdeal()) {
644 outputUnion.setLong(input.ideal());
645 }
646 }
647 return outputUnion;
605 } 648 }
606 649
607 ConstrainDoubleRange convertDouble(const DoubleConstraint& input) 650 DoubleOrConstrainDoubleRange convertDouble(const DoubleConstraint& input)
608 { 651 {
609 652 DoubleOrConstrainDoubleRange outputUnion;
610 ConstrainDoubleRange output; 653 if (input.hasExact() || input.hasMin() || input.hasMax()) {
611 if (input.hasExact()) 654 ConstrainDoubleRange output;
612 output.setExact(input.exact()); 655 if (input.hasExact())
613 if (input.hasIdeal()) 656 output.setExact(input.exact());
614 output.setIdeal(input.ideal()); 657 if (input.hasIdeal())
615 if (input.hasMin()) 658 output.setIdeal(input.ideal());
616 output.setMin(input.min()); 659 if (input.hasMin())
617 if (input.hasMax()) 660 output.setMin(input.min());
618 output.setMax(input.max()); 661 if (input.hasMax())
619 return output; 662 output.setMax(input.max());
663 outputUnion.setConstrainDoubleRange(output);
664 } else {
665 if (input.hasIdeal()) {
666 outputUnion.setDouble(input.ideal());
667 }
668 }
669 return outputUnion;
620 } 670 }
621 671
622 ConstrainDOMStringParameters convertString(const StringConstraint& input) 672 StringOrStringSequence convertStringSequence(const WebVector<WebString>& input)
623 { 673 {
624 ConstrainDOMStringParameters output; 674 StringOrStringSequence theStrings;
625 if (input.hasIdeal()) { 675 if (input.size() > 1) {
626 Vector<String> buffer; 676 Vector<String> buffer;
627 for (const auto& scanner : input.ideal()) 677 for (const auto& scanner : input)
628 buffer.append(scanner); 678 buffer.append(scanner);
629 output.setIdeal(buffer); 679 theStrings.setStringSequence(buffer);
680 } else if (input.size() > 0) {
681 theStrings.setString(input[0]);
630 } 682 }
631 if (input.hasExact()) { 683 return theStrings;
632 Vector<String> buffer;
633 for (const auto& scanner : input.exact())
634 buffer.append(scanner);
635 output.setExact(buffer);
636 }
637 return output;
638 } 684 }
639 685
640 ConstrainBooleanParameters convertBoolean(const BooleanConstraint& input) 686 StringOrStringSequenceOrConstrainDOMStringParameters convertString(const StringC onstraint& input)
641 { 687 {
688 StringOrStringSequenceOrConstrainDOMStringParameters outputUnion;
689 if (input.hasExact()) {
690 ConstrainDOMStringParameters output;
691 output.setExact(convertStringSequence(input.exact()));
692 if (input.hasIdeal()) {
693 output.setIdeal(convertStringSequence(input.ideal()));
694 }
695 outputUnion.setConstrainDOMStringParameters(output);
696 } else if (input.hasIdeal()) {
697 if (input.ideal().size() > 1) {
698 Vector<String> buffer;
699 for (const auto& scanner : input.ideal())
700 buffer.append(scanner);
701 outputUnion.setStringSequence(buffer);
702 } else if (input.ideal().size() == 1) {
703 outputUnion.setString(input.ideal()[0]);
704 }
705 }
706 return outputUnion;
707 }
642 708
643 ConstrainBooleanParameters output; 709 BooleanOrConstrainBooleanParameters convertBoolean(const BooleanConstraint& inpu t)
644 if (input.hasExact()) 710 {
645 output.setExact(input.exact()); 711 BooleanOrConstrainBooleanParameters outputUnion;
646 if (input.hasIdeal()) 712 if (input.hasExact()) {
647 output.setIdeal(input.ideal()); 713 ConstrainBooleanParameters output;
648 return output; 714 if (input.hasExact())
715 output.setExact(input.exact());
716 if (input.hasIdeal())
717 output.setIdeal(input.ideal());
718 outputUnion.setConstrainBooleanParameters(output);
719 } else if (input.hasIdeal()) {
720 outputUnion.setBoolean(input.ideal());
721 }
722 return outputUnion;
649 } 723 }
650 724
651 void convertConstraintSet(const WebMediaTrackConstraintSet& input, MediaTrackCon straintSet& output) 725 void convertConstraintSet(const WebMediaTrackConstraintSet& input, MediaTrackCon straintSet& output)
652 { 726 {
653 if (!input.width.isEmpty()) 727 if (!input.width.isEmpty())
654 output.setWidth(convertLong(input.width)); 728 output.setWidth(convertLong(input.width));
655 if (!input.height.isEmpty()) 729 if (!input.height.isEmpty())
656 output.setHeight(convertLong(input.height)); 730 output.setHeight(convertLong(input.height));
657 if (!input.aspectRatio.isEmpty()) 731 if (!input.aspectRatio.isEmpty())
658 output.setAspectRatio(convertDouble(input.aspectRatio)); 732 output.setAspectRatio(convertDouble(input.aspectRatio));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 MediaTrackConstraintSet element; 765 MediaTrackConstraintSet element;
692 convertConstraintSet(it, element); 766 convertConstraintSet(it, element);
693 advancedVector.append(element); 767 advancedVector.append(element);
694 } 768 }
695 if (!advancedVector.isEmpty()) 769 if (!advancedVector.isEmpty())
696 output.setAdvanced(advancedVector); 770 output.setAdvanced(advancedVector);
697 } 771 }
698 772
699 } // namespace MediaConstraintsImpl 773 } // namespace MediaConstraintsImpl
700 } // namespace blink 774 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698