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

playback_filling_state.patch
Thursday, March 27th, 2008 at 6:25:13pm UTC 

  1. diff --git a/apps/playback.c b/apps/playback.c
  2. index 421783e..4cdd721 100644
  3. --- a/apps/playback.c
  4. +++ b/apps/playback.c
  5. @@ -142,6 +142,14 @@ enum {
  6.  #endif
  7.  };
  8.  
  9. +enum filling_state {
  10. +    STATE_IDLE,
  11. +    STATE_WAITING,
  12. +    STATE_FILLING,
  13. +    STATE_FULL,
  14. +    STATE_FINISHED,
  15. +};
  16. +
  17.  /* As defined in plugins/lib/xxx2wav.h */
  18.  #if MEM > 1
  19.  #define MALLOC_BUFSIZE (512*1024)
  20. @@ -231,6 +239,8 @@ static int last_peek_offset = 0;
  21.  /* Scrobbler support */
  22.  static unsigned long prev_track_elapsed = 0; /* Previous track elapsed time (C/A-)*/
  23.  
  24. +static enum filling_state filling;
  25. +
  26.  /* Track change controls */
  27.  static bool automatic_skip = false; /* Who initiated in-progress skip? (C/A-) */
  28.  static bool playlist_end = false;   /* Has the current playlist ended? (A) */
  29. @@ -1493,9 +1503,13 @@ static void buffering_audio_callback(enum callback_event ev, int value)
  30.      switch (ev)
  31.      {
  32.          case EVENT_BUFFER_LOW:
  33. -            LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  34. -            queue_remove_from_head(&audio_queue, Q_AUDIO_FILL_BUFFER);
  35. -            queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  36. +            if (filling == STATE_WAITING || filling == STATE_FULL) {
  37. +                /* force a refill */
  38. +                filling = STATE_FILLING;
  39. +                LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  40. +                queue_remove_from_head(&audio_queue, Q_AUDIO_FILL_BUFFER);
  41. +                queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  42. +            }
  43.              break;
  44.  
  45.          case EVENT_HANDLE_REBUFFER:
  46. @@ -1709,6 +1723,8 @@ static bool audio_load_track(int offset, bool start_play)
  47.          logf("End-of-playlist");
  48.          playlist_end = true;
  49.          memset(&lasttrack_id3, 0, sizeof(struct mp3entry));
  50. +        filling = STATE_FINISHED;
  51. +        logf("finished buffering tracks");
  52.          return false;
  53.      }
  54.  
  55. @@ -1741,7 +1757,7 @@ static bool audio_load_track(int offset, bool start_play)
  56.                  last_peek_offset--;
  57.                  close(fd);
  58.                  copy_mp3entry(&lasttrack_id3, &id3);
  59. -                return false;
  60. +                goto buffer_full;
  61.              }
  62.  
  63.              if (track_widx == track_ridx)
  64. @@ -1806,7 +1822,7 @@ static bool audio_load_track(int offset, bool start_play)
  65.          if (tracks[track_widx].codec_hid == ERR_BUFFER_FULL)
  66.          {
  67.              /* No space for codec on buffer, not an error */
  68. -            return false;
  69. +            goto buffer_full;
  70.          }
  71.  
  72.          /* This is an error condition, either no codec was found, or reading
  73. @@ -1874,7 +1890,7 @@ static bool audio_load_track(int offset, bool start_play)
  74.      tracks[track_widx].audio_hid = bufopen(trackname, file_offset, type);
  75.  
  76.      if (tracks[track_widx].audio_hid < 0)
  77. -        return false;
  78. +        goto buffer_full;
  79.  
  80.      /* All required data is now available for the codec. */
  81.      tracks[track_widx].taginfo_ready = true;
  82. @@ -1888,6 +1904,11 @@ static bool audio_load_track(int offset, bool start_play)
  83.      track_widx = (track_widx + 1) & MAX_TRACK_MASK;
  84.  
  85.      return true;
  86. +
  87. +buffer_full:
  88. +    logf("buffer is full for now");
  89. +    filling = STATE_FULL;
  90. +    return false;
  91.  }
  92.  
  93.  static void audio_fill_file_buffer(bool start_play, size_t offset)
  94. @@ -1919,16 +1940,8 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  95.          start_play = false;
  96.          offset = 0;
  97.          sleep(1);
  98. -        if (queue_peek(&audio_queue, &ev)) {
  99. -            if (ev.id != Q_AUDIO_FILL_BUFFER)
  100. -            {
  101. -                /* There's a message in the queue. break the loop to treat it,
  102. -                and go back to filling after that. */
  103. -                LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  104. -                queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  105. -            }
  106. +        if (queue_peek(&audio_queue, &ev))
  107.              break;
  108. -        }
  109.      } while (continue_buffering);
  110.  
  111.      if (!had_next_track && audio_next_track())
  112. @@ -1953,6 +1966,7 @@ static void audio_rebuffer(void)
  113.      if (!CUR_TI->taginfo_ready)
  114.          memset(&curtrack_id3, 0, sizeof(struct mp3entry));
  115.  
  116. +    filling = STATE_FILLING;
  117.      audio_fill_file_buffer(false, 0);
  118.  }
  119.  
  120. @@ -2056,6 +2070,7 @@ static int audio_check_new_track(void)
  121.              {
  122.                  tracks[idx].audio_hid = -1;
  123.                  tracks[idx].filesize = 0;
  124. +                filling = STATE_WAITING;
  125.              }
  126.          }
  127.      }
  128. @@ -2182,6 +2197,8 @@ static void audio_stop_playback(void)
  129.      audio_stop_codec_flush();
  130.      playing = false;
  131.  
  132. +    filling = STATE_IDLE;
  133. +
  134.      /* Mark all entries null. */
  135.      audio_clear_track_entries();
  136.  
  137. @@ -2231,6 +2248,9 @@ static void audio_play_start(size_t offset)
  138.  #ifndef HAVE_FLASH_STORAGE
  139.      set_filebuf_watermark(buffer_margin, 0);
  140.  #endif
  141. +
  142. +    filling = STATE_FILLING;
  143. +
  144.      audio_fill_file_buffer(true, offset);
  145.      register_buffering_callback(buffering_audio_callback);
  146.  
  147. @@ -2414,11 +2434,17 @@ static void audio_thread(void)
  148.              queue_wait_w_tmo(&audio_queue, &ev, HZ/2);
  149.  
  150.          switch (ev.id) {
  151. +
  152.              case Q_AUDIO_FILL_BUFFER:
  153.                  LOGFQUEUE("audio < Q_AUDIO_FILL_BUFFER");
  154. -                if (!playing || playlist_end || ci.stop_codec)
  155. -                    break;
  156. -                audio_fill_file_buffer(false, 0);
  157. +                switch (filling) {
  158. +                    case STATE_WAITING:
  159. +                        audio_fill_file_buffer(false, 0);
  160. +                        break;
  161. +
  162. +                    default:
  163. +                        break;
  164. +                }
  165.                  break;
  166.  
  167.              case Q_AUDIO_PLAY:
  168. @@ -2434,6 +2460,7 @@ static void audio_thread(void)
  169.  
  170.              case Q_AUDIO_STOP:
  171.                  LOGFQUEUE("audio < Q_AUDIO_STOP");
  172. +                filling = STATE_IDLE;
  173.                  if (playing)
  174.                      audio_stop_playback();
  175.                  if (ev.data != 0)
  176. @@ -2520,6 +2547,8 @@ static void audio_thread(void)
  177.  
  178.              case SYS_TIMEOUT:
  179.                  LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT");
  180. +                if (filling == STATE_FILLING)
  181. +                    audio_fill_file_buffer(false, 0);
  182.                  break;
  183.  
  184.              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
worth-right
worth-right
worth-right