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

Miscellany
Friday, April 11th, 2008 at 2:14:52pm UTC 

  1. diff --git a/apps/buffering.c b/apps/buffering.c
  2. index 99a4a3b..13fbcbc 100644
  3. --- a/apps/buffering.c
  4. +++ b/apps/buffering.c
  5. @@ -50,6 +50,7 @@
  6.  #include "buffer.h"
  7.  #include "bmp.h"
  8.  #include "events.h"
  9. +#include "metadata.h"
  10.  
  11.  #ifdef SIMULATOR
  12.  #define ata_disk_is_active() 1
  13. @@ -586,6 +587,18 @@ static bool buffer_handle(int handle_id)
  14.  
  15.      trigger_cpu_boost();
  16.  
  17. +    if (h->type == TYPE_ID3)
  18. +    {
  19. +        get_metadata((struct mp3entry *)(buffer + h->data), h->fd, h->path);
  20. +        close(h->fd);
  21. +        h->fd = -1;
  22. +        h->filerem = 0;
  23. +        h->available = sizeof(struct mp3entry);
  24. +        h->widx += sizeof(struct mp3entry);
  25. +        send_event(EVENT_HANDLE_FINISHED, &h->id);
  26. +        return true;
  27. +    }
  28. +
  29.      while (h->filerem > 0)
  30.      {
  31.          /* max amount to copy */
  32. @@ -871,7 +884,31 @@ management functions for all the actual handle management work.
  33.  */
  34.  int bufopen(const char *file, size_t offset, enum data_type type)
  35.  {
  36. -    size_t adjusted_offset = offset;
  37. +    if (type == TYPE_ID3)
  38. +    {
  39. +        /* ID3 case: allocate space, init the handle and return. */
  40. +
  41. +        struct memory_handle *h = add_handle(sizeof(struct mp3entry), false, true);
  42. +        if (!h)
  43. +            return ERR_BUFFER_FULL;
  44. +
  45. +        h->fd = -1;
  46. +        h->filesize = sizeof(struct mp3entry);
  47. +        h->filerem = sizeof(struct mp3entry);
  48. +        h->offset = 0;
  49. +        h->data = buf_widx;
  50. +        h->ridx = buf_widx;
  51. +        h->widx = buf_widx;
  52. +        h->available = 0;
  53. +        h->type = type;
  54. +        strncpy(h->path, file, MAX_PATH);
  55. +
  56. +        buf_widx += sizeof(struct mp3entry);  /* safe because the handle
  57. +                                                 can't wrap */
  58. +        return h->id;
  59. +    }
  60. +
  61. +    /* Other cases: there is a little more work. */
  62.  
  63.      int fd = open(file, O_RDONLY);
  64.      if (fd < 0)
  65. @@ -880,6 +917,7 @@ int bufopen(const char *file, size_t offset, enum data_type type)
  66.      size_t size = filesize(fd);
  67.      bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC;
  68.  
  69. +    size_t adjusted_offset = offset;
  70.      if (adjusted_offset > size)
  71.          adjusted_offset = 0;
  72.  
  73. diff --git a/apps/playback.c b/apps/playback.c
  74. index 4d00eda..e8f8ba4 100644
  75. --- a/apps/playback.c
  76. +++ b/apps/playback.c
  77. @@ -131,6 +131,7 @@ enum {
  78.      Q_AUDIO_DIR_SKIP,
  79.      Q_AUDIO_POSTINIT,
  80.      Q_AUDIO_FILL_BUFFER,
  81. +    Q_AUDIO_FINISH_LOAD,
  82.      Q_CODEC_REQUEST_COMPLETE,
  83.      Q_CODEC_REQUEST_FAILED,
  84.  
  85. @@ -249,6 +250,9 @@ static bool new_playlist = false;   /* Are we starting a new playlist? (A) */
  86.  static int wps_offset = 0;          /* Pending track change offset, to keep WPS responsive (A) */
  87.  static bool skipped_during_pause = false; /* Do we need to clear the PCM buffer when playback resumes (A) */
  88.  
  89. +static bool start_play_g = false; /* Used by audio_load_track to notify
  90. +                                     audio_finish_load_track about start_play */
  91. +
  92.  /* Set to true if the codec thread should send an audio stop request
  93.   * (typically because the end of the playlist has been reached).
  94.   */
  95. @@ -607,6 +611,9 @@ struct mp3entry* audio_next_track(void)
  96.  
  97.      next_idx = (track_ridx + offset + 1) & MAX_TRACK_MASK;
  98.  
  99. +    if (tracks[next_idx].id3_hid >= 0)
  100. +        return bufgetid3(tracks[next_idx].id3_hid);
  101. +
  102.      if (next_idx == track_widx)
  103.      {
  104.          /* The next track hasn't been buffered yet, so we return the static
  105. @@ -614,10 +621,7 @@ struct mp3entry* audio_next_track(void)
  106.          return &lasttrack_id3;
  107.      }
  108.  
  109. -    if (tracks[next_idx].id3_hid < 0)
  110. -        return NULL;
  111. -    else
  112. -        return bufgetid3(tracks[next_idx].id3_hid);
  113. +    return NULL;
  114.  }
  115.  
  116.  bool audio_has_changed_track(void)
  117. @@ -1409,7 +1413,15 @@ static void buffering_handle_rebuffer_callback(void *data)
  118.  static void buffering_handle_finished_callback(int *data)
  119.  {
  120.      logf("handle %d finished buffering", *data);
  121. -    strip_tags(*data);
  122. +
  123. +    if (*data == tracks[track_widx].id3_hid) {
  124. +        DEBUGF("ID3 handle n° %d ready\n", *data);
  125. +        LOGFQUEUE("audio >| audio Q_AUDIO_FINISH_LOAD");
  126. +        queue_post(&audio_queue, Q_AUDIO_FINISH_LOAD, 0);
  127. +    } else {
  128. +        DEBUGF("handle n° %d ready\n", *data);
  129. +        strip_tags(*data);
  130. +    }
  131.  }
  132.  
  133.  
  134. @@ -1442,12 +1454,10 @@ long audio_filebufused(void)
  135.  static void audio_update_trackinfo(void)
  136.  {
  137.      /* Load the curent track's metadata into curtrack_id3 */
  138. -    CUR_TI->taginfo_ready = (CUR_TI->id3_hid >= 0);
  139.      if (CUR_TI->id3_hid >= 0)
  140.          copy_mp3entry(&curtrack_id3, bufgetid3(CUR_TI->id3_hid));
  141.  
  142.      int next_idx = (track_ridx + 1) & MAX_TRACK_MASK;
  143. -    tracks[next_idx].taginfo_ready = (tracks[next_idx].id3_hid >= 0);
  144.  
  145.      /* Reset current position */
  146.      curtrack_id3.elapsed = 0;
  147. @@ -1561,10 +1571,11 @@ static bool audio_loadcodec(bool start_play)
  148.  static bool audio_load_track(int offset, bool start_play)
  149.  {
  150.      const char *trackname;
  151. -    char msgbuf[80];
  152.      int fd = -1;
  153.      int file_offset = 0;
  154. -    struct mp3entry id3;
  155. +    struct mp3entry *id3;
  156. +
  157. +    start_play_g = start_play;  /* will be read by audio_finish_load_track */
  158.  
  159.      /* Stop buffer filling if there is no free track entries.
  160.         Don't fill up the last track entry (we wan't to store next track
  161. @@ -1621,46 +1632,51 @@ static bool audio_load_track(int offset, bool start_play)
  162.      /* Get track metadata if we don't already have it. */
  163.      if (tracks[track_widx].id3_hid < 0)
  164.      {
  165. -        if (get_metadata(&id3, fd, trackname))
  166. -        {
  167. -            id3.index = playlist_get_display_index() + last_peek_offset - 1;
  168. +            /* send_event(PLAYBACK_EVENT_TRACK_BUFFER, &id3); */
  169.  
  170. -            send_event(PLAYBACK_EVENT_TRACK_BUFFER, &id3);
  171. -
  172. -            tracks[track_widx].id3_hid =
  173. -                bufalloc(&id3, sizeof(struct mp3entry), TYPE_ID3);
  174. +            tracks[track_widx].id3_hid = bufopen(trackname, 0, TYPE_ID3);
  175.  
  176.              if (tracks[track_widx].id3_hid < 0)
  177.              {
  178.                  last_peek_offset--;
  179.                  close(fd);
  180. -                copy_mp3entry(&lasttrack_id3, &id3);
  181. +                /* copy_mp3entry(&lasttrack_id3, &id3); */
  182.                  goto buffer_full;
  183.              }
  184.  
  185. -            if (track_widx == track_ridx)
  186. -                copy_mp3entry(&curtrack_id3, &id3);
  187. +            if (start_play)
  188. +                buf_request_buffer_handle(tracks[track_widx].id3_hid);
  189. +
  190. +            if (track_widx == track_ridx) {
  191. +                copy_mp3entry(&curtrack_id3, bufgetid3(tracks[track_widx].id3_hid));
  192. +                curtrack_id3.offset = offset;
  193. +            }
  194.  
  195.              if (start_play)
  196.              {
  197.                  track_changed = true;
  198.                  playlist_update_resume_info(audio_current_track());
  199.              }
  200. -        }
  201. -        else
  202. -        {
  203. -            logf("mde:%s!",trackname);
  204. -
  205. -            /* Skip invalid entry from playlist. */
  206. -            playlist_skip_entry(NULL, last_peek_offset);
  207. -            close(fd);
  208. -            goto peek_again;
  209. -        }
  210.  
  211.      }
  212.  
  213.      close(fd);
  214.  
  215. +    return true;
  216. +
  217. +buffer_full:
  218. +    logf("buffer is full for now");
  219. +    filling = STATE_FULL;
  220. +    return false;
  221. +}
  222. +
  223. +static bool audio_finish_load_track(void)
  224. +{
  225. +    char msgbuf[80];
  226. +    int file_offset = 0;
  227. +    bool start_play = start_play_g;
  228. +    int offset = 0;
  229. +
  230.  #if 0
  231.      if (cuesheet_is_enabled() && tracks[track_widx].id3.cuesheet_type == 1)
  232.      {
  233. @@ -1678,6 +1694,9 @@ static bool audio_load_track(int offset, bool start_play)
  234.      }
  235.  #endif
  236.  
  237. +    if (tracks[track_widx].id3_hid < 0)
  238. +        return false;
  239. +
  240.      struct mp3entry *track_id3;
  241.  
  242.      if (track_widx == track_ridx)
  243. @@ -1700,20 +1719,21 @@ static bool audio_load_track(int offset, bool start_play)
  244.          if (tracks[track_widx].codec_hid == ERR_BUFFER_FULL)
  245.          {
  246.              /* No space for codec on buffer, not an error */
  247. -            goto buffer_full;
  248. +            return false;
  249.          }
  250.  
  251.          /* This is an error condition, either no codec was found, or reading
  252.           * the codec file failed part way through, either way, skip the track */
  253. -        snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", trackname);
  254. +        snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", track_id3->path);
  255.          /* We should not use gui_syncplash from audio thread! */
  256.          gui_syncsplash(HZ*2, msgbuf);
  257.          /* Skip invalid entry from playlist. */
  258.          playlist_skip_entry(NULL, last_peek_offset);
  259. -        goto peek_again;
  260. +        return false;
  261.      }
  262.  
  263.      track_id3->elapsed = 0;
  264. +    offset = track_id3->offset;
  265.  
  266.      enum data_type type = TYPE_PACKET_AUDIO;
  267.  
  268. @@ -1755,7 +1775,7 @@ static bool audio_load_track(int offset, bool start_play)
  269.          break;
  270.      }
  271.  
  272. -    logf("alt:%s", trackname);
  273. +    logf("alt:%s", track_id3->path);
  274.  
  275.      if (file_offset > AUDIO_REBUFFER_GUESS_SIZE)
  276.          file_offset -= AUDIO_REBUFFER_GUESS_SIZE;
  277. @@ -1764,10 +1784,10 @@ static bool audio_load_track(int offset, bool start_play)
  278.      else
  279.          file_offset = 0;
  280.  
  281. -    tracks[track_widx].audio_hid = bufopen(trackname, file_offset, type);
  282. +    tracks[track_widx].audio_hid = bufopen(track_id3->path, file_offset, type);
  283.  
  284.      if (tracks[track_widx].audio_hid < 0)
  285. -        goto buffer_full;
  286. +        return false;
  287.  
  288.      /* All required data is now available for the codec. */
  289.      tracks[track_widx].taginfo_ready = true;
  290. @@ -1780,12 +1800,11 @@ static bool audio_load_track(int offset, bool start_play)
  291.  
  292.      track_widx = (track_widx + 1) & MAX_TRACK_MASK;
  293.  
  294. -    return true;
  295. +    /* load next track */
  296. +    LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  297. +    queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  298.  
  299. -buffer_full:
  300. -    logf("buffer is full for now");
  301. -    filling = STATE_FULL;
  302. -    return false;
  303. +    return true;
  304.  }
  305.  
  306.  static void audio_fill_file_buffer(bool start_play, size_t offset)
  307. @@ -1815,6 +1834,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  308.      playlist_update_resume_info(audio_current_track());
  309.  
  310.      continue_buffering = audio_load_track(offset, start_play);
  311. +#if 0
  312.      do {
  313.          sleep(1);
  314.          if (!queue_empty(&audio_queue))
  315. @@ -1822,6 +1842,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  316.              break;
  317.          continue_buffering = audio_load_track(0, false);
  318.      } while (continue_buffering);
  319. +#endif
  320.  
  321.      if (!had_next_track && audio_next_track())
  322.          track_changed = true;
  323. @@ -2196,22 +2217,22 @@ static void audio_finalise_track_change(void)
  324.      {
  325.          wps_offset = 0;
  326.          automatic_skip = false;
  327. -    }
  328.  
  329. -    /* Invalidate prevtrack_id3 */
  330. -    prevtrack_id3.path[0] = 0;
  331. +        /* Invalidate prevtrack_id3 */
  332. +        prevtrack_id3.path[0] = 0;
  333.  
  334. -    if (prev_ti && prev_ti->audio_hid < 0)
  335. -    {
  336. -        /* No audio left so we clear all the track info. */
  337. -        clear_track_info(prev_ti);
  338. -    }
  339. +        if (prev_ti && prev_ti->audio_hid < 0)
  340. +        {
  341. +            /* No audio left so we clear all the track info. */
  342. +            clear_track_info(prev_ti);
  343. +        }
  344.  
  345. -    if (prev_ti && prev_ti->id3_hid >= 0)
  346. -    {
  347. -        /* Reset the elapsed time to force the progressbar to be empty if
  348. -           the user skips back to this track */
  349. -        bufgetid3(prev_ti->id3_hid)->elapsed = 0;
  350. +        if (prev_ti && prev_ti->id3_hid >= 0)
  351. +        {
  352. +            /* Reset the elapsed time to force the progressbar to be empty if
  353. +            the user skips back to this track */
  354. +            bufgetid3(prev_ti->id3_hid)->elapsed = 0;
  355. +        }
  356.      }
  357.  
  358.      send_event(PLAYBACK_EVENT_TRACK_CHANGE, &curtrack_id3);
  359. @@ -2298,6 +2319,11 @@ static void audio_thread(void)
  360.                  audio_fill_file_buffer(false, 0);
  361.                  break;
  362.  
  363. +            case Q_AUDIO_FINISH_LOAD:
  364. +                LOGFQUEUE("audio < Q_AUDIO_FINISH_LOAD");
  365. +                audio_finish_load_track();
  366. +                break;
  367. +
  368.              case Q_AUDIO_PLAY:
  369.                  LOGFQUEUE("audio < Q_AUDIO_PLAY");
  370.                  if (playing && ev.data <= 0)
  371. @@ -2397,8 +2423,8 @@ static void audio_thread(void)
  372.  
  373.              case SYS_TIMEOUT:
  374.                  LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT");
  375. -                if (filling == STATE_FILLING)
  376. -                    audio_fill_file_buffer(false, 0);
  377. +                /* if (filling == STATE_FILLING)
  378. +                    audio_fill_file_buffer(false, 0); */
  379.                  break;
  380.  
  381.              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