How do you adjust the size of Input and Output Buffers used by Android MediaCodec?











up vote
0
down vote

favorite












I am trying to process audio signal data while streaming at the same time, using Android AudioTrack/MediaCodec APIs.



The audio data must be cut into frames(windows) of certain sizes (1024 in my case) before I do any further analysis, which is why I was trying to change the size of input and output buffers going into the MediaCodec so that they are of the same size as, or multiples of the frame sizes.



readBuffer = ByteBuffer.allocate(2048);
writeBuffer = ByteBuffer.allocate(2048);


Code above allocates byte buffers of capacity 2048 to readBuffer and writeBuffer, as I verified by logging readBuffer.capacity().



However, these two lines of code seem to dequeue an input buffer with a much larger capacity (readBuffer.capacity(): 196608):



inputBufIndex = codec.dequeueInputBuffer(1000);
readBuffer = codec.getInputBuffer(inputBufIndex);


I have three questions:




  1. How is the size of the result buffer of codec.getInputBuffer() determined? Does it depend on the media format used?


  2. As described above, is it correct to match the buffer size with the frame size if I want to stream and analyze the audio data simultaneously?


  3. How would you resize the input and output buffers that go through the MediaCodec?











share|improve this question




























    up vote
    0
    down vote

    favorite












    I am trying to process audio signal data while streaming at the same time, using Android AudioTrack/MediaCodec APIs.



    The audio data must be cut into frames(windows) of certain sizes (1024 in my case) before I do any further analysis, which is why I was trying to change the size of input and output buffers going into the MediaCodec so that they are of the same size as, or multiples of the frame sizes.



    readBuffer = ByteBuffer.allocate(2048);
    writeBuffer = ByteBuffer.allocate(2048);


    Code above allocates byte buffers of capacity 2048 to readBuffer and writeBuffer, as I verified by logging readBuffer.capacity().



    However, these two lines of code seem to dequeue an input buffer with a much larger capacity (readBuffer.capacity(): 196608):



    inputBufIndex = codec.dequeueInputBuffer(1000);
    readBuffer = codec.getInputBuffer(inputBufIndex);


    I have three questions:




    1. How is the size of the result buffer of codec.getInputBuffer() determined? Does it depend on the media format used?


    2. As described above, is it correct to match the buffer size with the frame size if I want to stream and analyze the audio data simultaneously?


    3. How would you resize the input and output buffers that go through the MediaCodec?











    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am trying to process audio signal data while streaming at the same time, using Android AudioTrack/MediaCodec APIs.



      The audio data must be cut into frames(windows) of certain sizes (1024 in my case) before I do any further analysis, which is why I was trying to change the size of input and output buffers going into the MediaCodec so that they are of the same size as, or multiples of the frame sizes.



      readBuffer = ByteBuffer.allocate(2048);
      writeBuffer = ByteBuffer.allocate(2048);


      Code above allocates byte buffers of capacity 2048 to readBuffer and writeBuffer, as I verified by logging readBuffer.capacity().



      However, these two lines of code seem to dequeue an input buffer with a much larger capacity (readBuffer.capacity(): 196608):



      inputBufIndex = codec.dequeueInputBuffer(1000);
      readBuffer = codec.getInputBuffer(inputBufIndex);


      I have three questions:




      1. How is the size of the result buffer of codec.getInputBuffer() determined? Does it depend on the media format used?


      2. As described above, is it correct to match the buffer size with the frame size if I want to stream and analyze the audio data simultaneously?


      3. How would you resize the input and output buffers that go through the MediaCodec?











      share|improve this question















      I am trying to process audio signal data while streaming at the same time, using Android AudioTrack/MediaCodec APIs.



      The audio data must be cut into frames(windows) of certain sizes (1024 in my case) before I do any further analysis, which is why I was trying to change the size of input and output buffers going into the MediaCodec so that they are of the same size as, or multiples of the frame sizes.



      readBuffer = ByteBuffer.allocate(2048);
      writeBuffer = ByteBuffer.allocate(2048);


      Code above allocates byte buffers of capacity 2048 to readBuffer and writeBuffer, as I verified by logging readBuffer.capacity().



      However, these two lines of code seem to dequeue an input buffer with a much larger capacity (readBuffer.capacity(): 196608):



      inputBufIndex = codec.dequeueInputBuffer(1000);
      readBuffer = codec.getInputBuffer(inputBufIndex);


      I have three questions:




      1. How is the size of the result buffer of codec.getInputBuffer() determined? Does it depend on the media format used?


      2. As described above, is it correct to match the buffer size with the frame size if I want to stream and analyze the audio data simultaneously?


      3. How would you resize the input and output buffers that go through the MediaCodec?








      java android audio signal-processing codec






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday

























      asked Nov 7 at 7:39









      user3052069

      6719




      6719





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185230%2fhow-do-you-adjust-the-size-of-input-and-output-buffers-used-by-android-mediacode%23new-answer', 'question_page');
          }
          );

          Post as a guest





































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185230%2fhow-do-you-adjust-the-size-of-input-and-output-buffers-used-by-android-mediacode%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          FTSE 250 Index