Skip to content
Snippets Groups Projects
  1. Mar 17, 2015
  2. Mar 14, 2015
  3. Mar 13, 2015
  4. Mar 12, 2015
    • Matthew Jordan's avatar
      main/audiohook: Update internal sample rate on reads · 38ee441e
      Matthew Jordan authored
      When an audiohook is created (which is used by the various Spy applications
      and Snoop channel in Asterisk 13+), it initially is given a sample rate of
      8kHz. It is expected, however, that this rate may change based on the media
      that passes through the audiohook. However, the read/write operations on the
      audiohook behave very differently.
      
      When a frame is written to the audiohook, the format of the frame is checked
      against the internal sample rate. If the rate of the format does not match
      the internal sample rate, the internal sample rate is updated and a new SLIN
      format is chosen based on that sample rate. This works just fine.
      
      When a frame is read, however, we do something quite different. If the format
      rate matches the internal sample rate, all is fine. However, if the rates
      don't match, the audiohook attempts to "fix up" the number of samples that
      were requested. This can result in some seriously large number of samples
      being requested from the read/write factories.
      
      Consider the worst case - 192kHz SLIN. If we attempt to read 20ms worth of
      audio produced at that rate, we'd request 3840 samples (192000 / (1000 / 20)).
      However, if the audiohook is still expecting an internal sample rate of 8000,
      we'll attempt to "fix up" the requested samples to:
      
        samples_converted = samples * (ast_format_get_sample_rate(format) /
                                       (float) audiohook->hook_internal_samp_rate);
      
        which is:
      
        92160 = 3840 * (192000 / 8000)
      
      This results in us attempting to read 92160 samples from our factories, as
      opposed to the 3840 that we actually wanted. On a 64-bit machine, this
      miraculously survives - despite allocating up to two buffers of length 92160
      on the stack. The 32-bit machines aren't quite so lucky. Even in the case where
      this works, we will either (a) get way more samples than we wanted; or (b) get
      about 3840 samples, assuming the timing is pretty good on the machine.
      
      Either way, the calculation being performed is wrong, based on the API users
      expectations.
      
      My first inclination was to allocate the buffers on the heap. As it is,
      however, there's at least two drawbacks with doing this:
      (1) It's a bit complicated, as the size of the buffers may change during the
          lifetime of the audiohook (ew).
      (2) The stack is faster (yay); the heap is slower (boo).
      
      Since our calculation is flat out wrong in the first place, this patch fixes
      this issue by instead updating the internal sample rate based on the format
      passed into the read operation. This causes us to read the correct number of
      samples, and has the added benefit of setting the audihook with the right
      SLIN format.
      
      Note that this issue was caught by the Asterisk Test Suite as a result of
      r432195 in the 13 branch. Because this issue is also theoretically possible
      in Asterisk 11, the change is being made here as well.
      
      Review: https://reviewboard.asterisk.org/r/4475/
      ........
      
      Merged revisions 432810 from http://svn.asterisk.org/svn/asterisk/branches/11
      ........
      
      Merged revisions 432811 from http://svn.asterisk.org/svn/asterisk/branches/13
      
      
      git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432812 65c4cc65-6c06-0410-ace0-fbb531ad65f3
      38ee441e
    • Matthew Jordan's avatar
      Add support for the clang compiler; update RAII_VAR to use BlocksRuntime · 29304d10
      Matthew Jordan authored
      RAII_VAR, which is used extensively in Asterisk to manage reference counted
      resources, uses a GCC extension to automatically invoke a cleanup function
      when a variable loses scope. While this functionality is incredibly useful
      and has prevented a large number of memory leaks, it also prevents Asterisk
      from being compiled with clang.
      
      This patch updates the RAII_VAR macro such that it can be compiled with clang.
      It makes use of the BlocksRuntime, which allows for a closure to be created
      that performs the actual cleanup.
      
      Note that this does not attempt to address the numerous warnings that the clang
      compiler catches in Asterisk.
      
      Much thanks for this patch goes to:
      * The folks on StackOverflow who asked this question and Leushenko for
        providing the answer that formed the basis of this code:
        http://stackoverflow.com/questions/24959440/rewrite-gcc-cleanup-macro-with-nested-function-for-clang
      * Diederik de Groot, who has been extremely patient in working on getting this
        patch into Asterisk.
      
      Review: https://reviewboard.asterisk.org/r/4370/
      
      ASTERISK-24133
      ASTERISK-23666
      ASTERISK-20399
      ASTERISK-20850 #close
      Reported by: Diederik de Groot
      patches:
        RAII_CLANG.patch uploaded by Diederik de Groot (License 6600)
      ........
      
      Merged revisions 432807 from http://svn.asterisk.org/svn/asterisk/branches/11
      ........
      
      Merged revisions 432808 from http://svn.asterisk.org/svn/asterisk/branches/13
      
      
      git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432809 65c4cc65-6c06-0410-ace0-fbb531ad65f3
      29304d10
  5. Mar 11, 2015
  6. Mar 10, 2015
  7. Mar 09, 2015
  8. Mar 08, 2015
  9. Mar 06, 2015
  10. Mar 05, 2015
  11. Mar 04, 2015
    • Matthew Jordan's avatar
      translate: Prevent invalid memory accesses on fast shutdown · 41ba8fd7
      Matthew Jordan authored
      When a 'core restart now' or 'core stop now' is executed and a channel is
      currently in a media operation, the translator matrix can be destroyed while a
      channel is currently blocked on getting the best translation choice
      (see ast_translator_best_choice). When the channel gets the mutex, the
      translation matrix now has invalid memory, and Asterisk crashes.
      
      This patch does two things:
      (1) We now only clean up the translation matrix on a graceful shutdown. In that
          case, there are no channels, and so there is no risk of this occurring.
      (2) We also now set the __matrix and __indextable to NULL. In some initial
          backtraces when this occurred, it looked as if there was a memory corruption
          occurring, and it wasn't until we determined that something had restarted
          Asterisk that the issue became clear. By setting these to NULL on shutdown,
          it becomes a bit easier to determine why a crash is occurring.
      
      Note that we could litter the code with NULL checks on the __matrix, but the
      act of making the translation matrix cleaned up on shutdown should preclude
      this issue from occurring in the first place, and this part of the code needs
      to be as fast as possible.
      
      Review: https://reviewboard.asterisk.org/r/4457/
      ........
      
      Merged revisions 432453 from http://svn.asterisk.org/svn/asterisk/branches/13
      
      
      git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432455 65c4cc65-6c06-0410-ace0-fbb531ad65f3
      41ba8fd7
  12. Mar 02, 2015
  13. Feb 27, 2015
  14. Feb 26, 2015
    • Scott Griepentrog's avatar
      Dial API: add self destruct option when complete · d79670b2
      Scott Griepentrog authored
      This patch adds a self-destruction option to the
      dial api.  The usefulness of this is mostly when
      using async mode to spawn a separate thread used
      to handle the new call, while the calling thread
      is allowed to go on about other business.
      
      The only alternative to this option would be the
      calling thread spawning a new thread, or hanging
      around itself waiting to destroy the dial struct
      after completion.
      
      Example of use (minus error checking):
      
        struct ast_dial *dial = ast_dial_create();
      
        ast_dial_append(dial, "PJSIP", "200", NULL);
      
        ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, "Echo");
        ast_dial_option_global_enable(dial, AST_DIAL_OPTION_SELF_DESTROY, NULL);
      
        ast_dial_run(dial, NULL, 1);
      
      The dial_run call will return almost immediately
      after spawning the new thread to run and monitor
      the dial.  If the call is answered, it is placed
      into the echo app.  When completed, it will call
      ast_dial_destroy() on the dial structure.
      
      Note that any allocations made to pass values to
      ast_dial_set_user_data() or dial options must be
      free'd in a state callback function on any of:
        AST_DIAL_RESULT_UNASWERED,
        AST_DIAL_RESULT_ANSWERED,
        AST_DIAL_RESULT_HANGUP, or 
        AST_DIAL_RESULT_TIMEOUT.
      
      Review: https://reviewboard.asterisk.org/r/4443/
      ........
      
      Merged revisions 432385 from http://svn.asterisk.org/svn/asterisk/branches/13
      
      
      git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432386 65c4cc65-6c06-0410-ace0-fbb531ad65f3
      d79670b2
Loading