Let AudioCodingModule::SendCodec return Maybe<CodecInst>

And deal with the consequences thereof...

Review URL: https://codereview.webrtc.org/1406123011

Cr-Commit-Position: refs/heads/master@{#10497}
diff --git a/webrtc/modules/audio_coding/main/test/APITest.cc b/webrtc/modules/audio_coding/main/test/APITest.cc
index 1313f35..81880be 100644
--- a/webrtc/modules/audio_coding/main/test/APITest.cc
+++ b/webrtc/modules/audio_coding/main/test/APITest.cc
@@ -823,9 +823,11 @@
       exit(-1);
   }
 
-  CodecInst myCodec;
-  if (sendACM->SendCodec(&myCodec) < 0) {
-    AudioCodingModule::Codec(_codecCntrA, &myCodec);
+  auto myCodec = sendACM->SendCodec();
+  if (!myCodec) {
+    CodecInst ci;
+    AudioCodingModule::Codec(_codecCntrA, &ci);
+    myCodec = rtc::Maybe<CodecInst>(ci);
   }
 
   if (!_randomTest) {
@@ -837,12 +839,12 @@
     *thereIsDecoder = false;
   }
   //myEvent->Wait(20);
-  CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
+  CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype));
   Wait(1000);
 
-  int currentPayload = myCodec.pltype;
+  int currentPayload = myCodec->pltype;
 
-  if (!FixedPayloadTypeCodec(myCodec.plname)) {
+  if (!FixedPayloadTypeCodec(myCodec->plname)) {
     int32_t i;
     for (i = 0; i < 32; i++) {
       if (!_payloadUsed[i]) {
@@ -850,9 +852,9 @@
           fprintf(stdout,
                   "Register receive codec with new Payload, AUDIO BACK.\n");
         }
-        //myCodec.pltype = i + 96;
-        //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
-        //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec));
+        //myCodec->pltype = i + 96;
+        //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec));
+        //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec));
         //myEvent->Wait(20);
         //{
         //    WriteLockScoped wl(_apiTestRWLock);
@@ -868,17 +870,17 @@
         //    *thereIsDecoder = false;
         //}
         //myEvent->Wait(20);
-        //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
+        //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype));
         Wait(1000);
 
-        myCodec.pltype = currentPayload;
+        myCodec->pltype = currentPayload;
         if (!_randomTest) {
           fprintf(stdout,
                   "Register receive codec with default Payload, AUDIO BACK.\n");
           fflush (stdout);
         }
-        CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
-        //CHECK_ERROR_MT(sendACM->RegisterSendCodec(myCodec));
+        CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec));
+        //CHECK_ERROR_MT(sendACM->RegisterSendCodec(*myCodec));
         myEvent->Wait(20);
         {
           WriteLockScoped wl(_apiTestRWLock);
@@ -890,7 +892,7 @@
       }
     }
     if (i == 32) {
-      CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
+      CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec));
       {
         WriteLockScoped wl(_apiTestRWLock);
         *thereIsDecoder = true;
@@ -902,9 +904,9 @@
               "Register receive codec with fixed Payload, AUDIO BACK.\n");
       fflush (stdout);
     }
-    CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
-    //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec.pltype));
-    //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(myCodec));
+    CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec));
+    //CHECK_ERROR_MT(receiveACM->UnregisterReceiveCodec(myCodec->pltype));
+    //CHECK_ERROR_MT(receiveACM->RegisterReceiveCodec(*myCodec));
     myEvent->Wait(20);
     {
       WriteLockScoped wl(_apiTestRWLock);
@@ -1001,22 +1003,17 @@
 }
 
 void APITest::CurrentCodec(char side) {
-  CodecInst myCodec;
-  if (side == 'A') {
-    _acmA->SendCodec(&myCodec);
-  } else {
-    _acmB->SendCodec(&myCodec);
-  }
+  auto myCodec = (side == 'A' ? _acmA : _acmB)->SendCodec();
 
   if (!_randomTest) {
     fprintf(stdout, "\n\n");
     fprintf(stdout, "Send codec in Side A\n");
     fprintf(stdout, "----------------------------\n");
-    fprintf(stdout, "Name................. %s\n", myCodec.plname);
-    fprintf(stdout, "Sampling Frequency... %d\n", myCodec.plfreq);
-    fprintf(stdout, "Rate................. %d\n", myCodec.rate);
-    fprintf(stdout, "Payload-type......... %d\n", myCodec.pltype);
-    fprintf(stdout, "Packet-size.......... %d\n", myCodec.pacsize);
+    fprintf(stdout, "Name................. %s\n", myCodec->plname);
+    fprintf(stdout, "Sampling Frequency... %d\n", myCodec->plfreq);
+    fprintf(stdout, "Rate................. %d\n", myCodec->rate);
+    fprintf(stdout, "Payload-type......... %d\n", myCodec->pltype);
+    fprintf(stdout, "Packet-size.......... %d\n", myCodec->pacsize);
   }
 
   Wait(100);
diff --git a/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc b/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc
index d062af0..d68e575 100644
--- a/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc
+++ b/webrtc/modules/audio_coding/main/test/EncodeDecodeTest.cc
@@ -339,8 +339,7 @@
   _sender.codeId = codeId;
 
   _sender.Setup(acm.get(), &rtpFile, "audio_coding/testfile32kHz", 32000, 1);
-  struct CodecInst sendCodecInst;
-  if (acm->SendCodec(&sendCodecInst) >= 0) {
+  if (acm->SendCodec()) {
     _sender.Run();
   }
   _sender.Teardown();
diff --git a/webrtc/modules/audio_coding/main/test/PacketLossTest.cc b/webrtc/modules/audio_coding/main/test/PacketLossTest.cc
index f19d491..f7c96fa 100644
--- a/webrtc/modules/audio_coding/main/test/PacketLossTest.cc
+++ b/webrtc/modules/audio_coding/main/test/PacketLossTest.cc
@@ -143,8 +143,7 @@
 
   sender_->Setup(acm.get(), &rtpFile, in_file_name_, sample_rate_hz_, channels_,
                  expected_loss_rate_);
-  struct CodecInst sendCodecInst;
-  if (acm->SendCodec(&sendCodecInst) >= 0) {
+  if (acm->SendCodec()) {
     sender_->Run();
   }
   sender_->Teardown();
diff --git a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
index 19189b6..e9e4f2b 100644
--- a/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
+++ b/webrtc/modules/audio_coding/main/test/TestAllCodecs.cc
@@ -477,8 +477,7 @@
 
 void TestAllCodecs::DisplaySendReceiveCodec() {
   CodecInst my_codec_param;
-  acm_a_->SendCodec(&my_codec_param);
-  printf("%s -> ", my_codec_param.plname);
+  printf("%s -> ", acm_a_->SendCodec()->plname);
   acm_b_->ReceiveCodec(&my_codec_param);
   printf("%s\n", my_codec_param.plname);
 }
diff --git a/webrtc/modules/audio_coding/main/test/TestStereo.cc b/webrtc/modules/audio_coding/main/test/TestStereo.cc
index 69cc327..bb38fac 100644
--- a/webrtc/modules/audio_coding/main/test/TestStereo.cc
+++ b/webrtc/modules/audio_coding/main/test/TestStereo.cc
@@ -823,14 +823,15 @@
 }
 
 void TestStereo::DisplaySendReceiveCodec() {
-  CodecInst my_codec_param;
-  acm_a_->SendCodec(&my_codec_param);
+  auto send_codec = acm_a_->SendCodec();
   if (test_mode_ != 0) {
-    printf("%s -> ", my_codec_param.plname);
+    ASSERT_TRUE(send_codec);
+    printf("%s -> ", send_codec->plname);
   }
-  acm_b_->ReceiveCodec(&my_codec_param);
+  CodecInst receive_codec;
+  acm_b_->ReceiveCodec(&receive_codec);
   if (test_mode_ != 0) {
-    printf("%s\n", my_codec_param.plname);
+    printf("%s\n", receive_codec.plname);
   }
 }
 
diff --git a/webrtc/modules/audio_coding/main/test/TestVADDTX.cc b/webrtc/modules/audio_coding/main/test/TestVADDTX.cc
index bd0335a..bba7b91 100644
--- a/webrtc/modules/audio_coding/main/test/TestVADDTX.cc
+++ b/webrtc/modules/audio_coding/main/test/TestVADDTX.cc
@@ -209,9 +209,9 @@
   EXPECT_EQ(0, acm_send_->SetVAD(enable_dtx, enable_vad, vad_mode));
   EXPECT_EQ(0, acm_send_->VAD(&dtx_enabled_, &vad_enabled_, &mode));
 
-  CodecInst codec_param;
-  acm_send_->SendCodec(&codec_param);
-  if (STR_CASE_CMP(codec_param.plname, "opus") == 0) {
+  auto codec_param = acm_send_->SendCodec();
+  ASSERT_TRUE(codec_param);
+  if (STR_CASE_CMP(codec_param->plname, "opus") == 0) {
     // If send codec is Opus, WebRTC VAD/DTX cannot be used.
     enable_dtx = enable_vad = false;
   }
diff --git a/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc b/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc
index 2ff2a85..725cbf7 100644
--- a/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc
+++ b/webrtc/modules/audio_coding/main/test/TwoWayCommunication.cc
@@ -250,10 +250,8 @@
 
   AudioFrame audioFrame;
 
-  CodecInst codecInst_B;
-  CodecInst dummy;
-
-  EXPECT_EQ(0, _acmB->SendCodec(&codecInst_B));
+  auto codecInst_B = _acmB->SendCodec();
+  ASSERT_TRUE(codecInst_B);
 
   // In the following loop we tests that the code can handle misuse of the APIs.
   // In the middle of a session with data flowing between two sides, called A
@@ -285,15 +283,15 @@
     }
     // Re-register send codec on side B.
     if (((secPassed % 5) == 4) && (msecPassed >= 990)) {
-      EXPECT_EQ(0, _acmB->RegisterSendCodec(codecInst_B));
-      EXPECT_EQ(0, _acmB->SendCodec(&dummy));
+      EXPECT_EQ(0, _acmB->RegisterSendCodec(*codecInst_B));
+      EXPECT_TRUE(_acmB->SendCodec());
     }
     // Initialize receiver on side A.
     if (((secPassed % 7) == 6) && (msecPassed == 0))
       EXPECT_EQ(0, _acmA->InitializeReceiver());
     // Re-register codec on side A.
     if (((secPassed % 7) == 6) && (msecPassed >= 990)) {
-      EXPECT_EQ(0, _acmA->RegisterReceiveCodec(codecInst_B));
+      EXPECT_EQ(0, _acmA->RegisterReceiveCodec(*codecInst_B));
     }
   }
 }
diff --git a/webrtc/modules/audio_coding/main/test/iSACTest.cc b/webrtc/modules/audio_coding/main/test/iSACTest.cc
index 35c34d5..203e12b 100644
--- a/webrtc/modules/audio_coding/main/test/iSACTest.cc
+++ b/webrtc/modules/audio_coding/main/test/iSACTest.cc
@@ -47,21 +47,21 @@
 
   if ((isacConfig.currentRateBitPerSec != 0)
       || (isacConfig.currentFrameSizeMsec != 0)) {
-    CodecInst sendCodec;
-    EXPECT_EQ(0, acm->SendCodec(&sendCodec));
+    auto sendCodec = acm->SendCodec();
+    EXPECT_TRUE(sendCodec);
     if (isacConfig.currentRateBitPerSec < 0) {
       // Register iSAC in adaptive (channel-dependent) mode.
-      sendCodec.rate = -1;
-      EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
+      sendCodec->rate = -1;
+      EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec));
     } else {
       if (isacConfig.currentRateBitPerSec != 0) {
-        sendCodec.rate = isacConfig.currentRateBitPerSec;
+        sendCodec->rate = isacConfig.currentRateBitPerSec;
       }
       if (isacConfig.currentFrameSizeMsec != 0) {
-        sendCodec.pacsize = isacConfig.currentFrameSizeMsec
-            * (sendCodec.plfreq / 1000);
+        sendCodec->pacsize = isacConfig.currentFrameSizeMsec
+            * (sendCodec->plfreq / 1000);
       }
-      EXPECT_EQ(0, acm->RegisterSendCodec(sendCodec));
+      EXPECT_EQ(0, acm->RegisterSendCodec(*sendCodec));
     }
   }
 
@@ -238,7 +238,6 @@
   _channel_B2A->ResetStats();
 
   char currentTime[500];
-  CodecInst sendCodec;
   EventTimerWrapper* myEvent = EventTimerWrapper::Create();
   EXPECT_TRUE(myEvent->StartTimer(true, 10));
   while (!(_inFileA.EndOfFile() || _inFileA.Rewinded())) {
@@ -248,8 +247,8 @@
 
     if ((adaptiveMode) && (_testMode != 0)) {
       myEvent->Wait(5000);
-      EXPECT_EQ(0, _acmA->SendCodec(&sendCodec));
-      EXPECT_EQ(0, _acmB->SendCodec(&sendCodec));
+      EXPECT_TRUE(_acmA->SendCodec());
+      EXPECT_TRUE(_acmB->SendCodec());
     }
   }