Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Mine
Thursday, March 27th, 2008 at 10:32:30pm UTC 

This post has 1 comment thread shown at the end of this page.

  1. diff --git a/apps/playback.c b/apps/playback.c
  2. index 421783e..07f658c 100644
  3. --- a/apps/playback.c
  4. +++ b/apps/playback.c
  5. @@ -142,6 +142,13 @@ enum {
  6.  #endif
  7.  };
  8.  
  9. +enum filling_state {
  10. +    STATE_IDLE,     /* audio is stopped: nothing to do */
  11. +    STATE_FILLING,  /* adding tracks to the buffer */
  12. +    STATE_FULL,     /* can't add any more tracks */
  13. +    STATE_FINISHED, /* all remaining tracks have been added */
  14. +};
  15. +
  16.  /* As defined in plugins/lib/xxx2wav.h */
  17.  #if MEM > 1
  18.  #define MALLOC_BUFSIZE (512*1024)
  19. @@ -231,6 +238,8 @@ static int last_peek_offset = 0;
  20.  /* Scrobbler support */
  21.  static unsigned long prev_track_elapsed = 0; /* Previous track elapsed time (C/A-)*/
  22.  
  23. +static enum filling_state filling;
  24. +
  25.  /* Track change controls */
  26.  static bool automatic_skip = false; /* Who initiated in-progress skip? (C/A-) */
  27.  static bool playlist_end = false;   /* Has the current playlist ended? (A) */
  28. @@ -1493,9 +1502,11 @@ static void buffering_audio_callback(enum callback_event ev, int value)
  29.      switch (ev)
  30.      {
  31.          case EVENT_BUFFER_LOW:
  32. -            LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  33. -            queue_remove_from_head(&audio_queue, Q_AUDIO_FILL_BUFFER);
  34. -            queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  35. +            if (filling == STATE_FULL) {
  36. +                /* force a refill */
  37. +                LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  38. +                queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  39. +            }
  40.              break;
  41.  
  42.          case EVENT_HANDLE_REBUFFER:
  43. @@ -1709,6 +1720,7 @@ static bool audio_load_track(int offset, bool start_play)
  44.          logf("End-of-playlist");
  45.          playlist_end = true;
  46.          memset(&lasttrack_id3, 0, sizeof(struct mp3entry));
  47. +        filling = STATE_FINISHED;
  48.          return false;
  49.      }
  50.  
  51. @@ -1741,7 +1753,7 @@ static bool audio_load_track(int offset, bool start_play)
  52.                  last_peek_offset--;
  53.                  close(fd);
  54.                  copy_mp3entry(&lasttrack_id3, &id3);
  55. -                return false;
  56. +                goto buffer_full;
  57.              }
  58.  
  59.              if (track_widx == track_ridx)
  60. @@ -1806,7 +1818,7 @@ static bool audio_load_track(int offset, bool start_play)
  61.          if (tracks[track_widx].codec_hid == ERR_BUFFER_FULL)
  62.          {
  63.              /* No space for codec on buffer, not an error */
  64. -            return false;
  65. +            goto buffer_full;
  66.          }
  67.  
  68.          /* This is an error condition, either no codec was found, or reading
  69. @@ -1874,7 +1886,7 @@ static bool audio_load_track(int offset, bool start_play)
  70.      tracks[track_widx].audio_hid = bufopen(trackname, file_offset, type);
  71.  
  72.      if (tracks[track_widx].audio_hid < 0)
  73. -        return false;
  74. +        goto buffer_full;
  75.  
  76.      /* All required data is now available for the codec. */
  77.      tracks[track_widx].taginfo_ready = true;
  78. @@ -1888,6 +1900,11 @@ static bool audio_load_track(int offset, bool start_play)
  79.      track_widx = (track_widx + 1) & MAX_TRACK_MASK;
  80.  
  81.      return true;
  82. +
  83. +buffer_full:
  84. +    logf("buffer is full for now");
  85. +    filling = STATE_FULL;
  86. +    return false;
  87.  }
  88.  
  89.  static void audio_fill_file_buffer(bool start_play, size_t offset)
  90. @@ -1896,6 +1913,8 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  91.      bool had_next_track = audio_next_track() != NULL;
  92.      bool continue_buffering;
  93.  
  94. +    filling = STATE_FILLING;
  95. +
  96.      /* No need to rebuffer if there are track skips pending. */
  97.      if (ci.new_track != 0)
  98.          return;
  99. @@ -1919,16 +1938,9 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  100.          start_play = false;
  101.          offset = 0;
  102.          sleep(1);
  103. -        if (queue_peek(&audio_queue, &ev)) {
  104. -            if (ev.id != Q_AUDIO_FILL_BUFFER)
  105. -            {
  106. -                /* There's a message in the queue. break the loop to treat it,
  107. -                and go back to filling after that. */
  108. -                LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  109. -                queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  110. -            }
  111. +        if (queue_peek(&audio_queue, &ev))
  112. +            /* There's a message in the queue. break the loop to treat it */
  113.              break;
  114. -        }
  115.      } while (continue_buffering);
  116.  
  117.      if (!had_next_track && audio_next_track())
  118. @@ -2182,6 +2194,8 @@ static void audio_stop_playback(void)
  119.      audio_stop_codec_flush();
  120.      playing = false;
  121.  
  122. +    filling = STATE_IDLE;
  123. +
  124.      /* Mark all entries null. */
  125.      audio_clear_track_entries();
  126.  
  127. @@ -2231,6 +2245,7 @@ static void audio_play_start(size_t offset)
  128.  #ifndef HAVE_FLASH_STORAGE
  129.      set_filebuf_watermark(buffer_margin, 0);
  130.  #endif
  131. +
  132.      audio_fill_file_buffer(true, offset);
  133.      register_buffering_callback(buffering_audio_callback);
  134.  
  135. @@ -2414,10 +2429,9 @@ static void audio_thread(void)
  136.              queue_wait_w_tmo(&audio_queue, &ev, HZ/2);
  137.  
  138.          switch (ev.id) {
  139. +
  140.              case Q_AUDIO_FILL_BUFFER:
  141.                  LOGFQUEUE("audio < Q_AUDIO_FILL_BUFFER");
  142. -                if (!playing || playlist_end || ci.stop_codec)
  143. -                    break;
  144.                  audio_fill_file_buffer(false, 0);
  145.                  break;
  146.  
  147. @@ -2520,6 +2534,8 @@ static void audio_thread(void)
  148.  
  149.              case SYS_TIMEOUT:
  150.                  LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT");
  151. +                if (filling == STATE_FILLING)
  152. +                    audio_fill_file_buffer(false, 0);
  153.                  break;
  154.  
  155.              default:

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus

comments on this paste

mine (#960166)

Posted: May 5th, 2014 at 1:29pm UTC

1

worth-right worth-right