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

Something
Friday, April 11th, 2008 at 10:30:51am 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..ca886a1 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. @@ -1409,7 +1410,15 @@ static void buffering_handle_rebuffer_callback(void *data)
  86.  static void buffering_handle_finished_callback(int *data)
  87.  {
  88.      logf("handle %d finished buffering", *data);
  89. -    strip_tags(*data);
  90. +
  91. +    if (*data == tracks[track_widx].id3_hid) {
  92. +        DEBUGF("ID3 handle n° %d ready\n", *data);
  93. +        LOGFQUEUE("audio >| audio Q_AUDIO_FINISH_LOAD");
  94. +        queue_post(&audio_queue, Q_AUDIO_FINISH_LOAD, 0);
  95. +    } else {
  96. +        DEBUGF("handle n° %d ready\n", *data);
  97. +        strip_tags(*data);
  98. +    }
  99.  }
  100.  
  101.  
  102. @@ -1442,12 +1451,10 @@ long audio_filebufused(void)
  103.  static void audio_update_trackinfo(void)
  104.  {
  105.      /* Load the curent track's metadata into curtrack_id3 */
  106. -    CUR_TI->taginfo_ready = (CUR_TI->id3_hid >= 0);
  107.      if (CUR_TI->id3_hid >= 0)
  108.          copy_mp3entry(&curtrack_id3, bufgetid3(CUR_TI->id3_hid));
  109.  
  110.      int next_idx = (track_ridx + 1) & MAX_TRACK_MASK;
  111. -    tracks[next_idx].taginfo_ready = (tracks[next_idx].id3_hid >= 0);
  112.  
  113.      /* Reset current position */
  114.      curtrack_id3.elapsed = 0;
  115. @@ -1561,10 +1568,9 @@ static bool audio_loadcodec(bool start_play)
  116.  static bool audio_load_track(int offset, bool start_play)
  117.  {
  118.      const char *trackname;
  119. -    char msgbuf[80];
  120.      int fd = -1;
  121.      int file_offset = 0;
  122. -    struct mp3entry id3;
  123. +    struct mp3entry *id3;
  124.  
  125.      /* Stop buffer filling if there is no free track entries.
  126.         Don't fill up the last track entry (we wan't to store next track
  127. @@ -1621,46 +1627,51 @@ static bool audio_load_track(int offset, bool start_play)
  128.      /* Get track metadata if we don't already have it. */
  129.      if (tracks[track_widx].id3_hid < 0)
  130.      {
  131. -        if (get_metadata(&id3, fd, trackname))
  132. -        {
  133. -            id3.index = playlist_get_display_index() + last_peek_offset - 1;
  134. -
  135. -            send_event(PLAYBACK_EVENT_TRACK_BUFFER, &id3);
  136. +            /* send_event(PLAYBACK_EVENT_TRACK_BUFFER, &id3); */
  137.  
  138. -            tracks[track_widx].id3_hid =
  139. -                bufalloc(&id3, sizeof(struct mp3entry), TYPE_ID3);
  140. +            tracks[track_widx].id3_hid = bufopen(trackname, 0, TYPE_ID3);
  141.  
  142.              if (tracks[track_widx].id3_hid < 0)
  143.              {
  144.                  last_peek_offset--;
  145.                  close(fd);
  146. -                copy_mp3entry(&lasttrack_id3, &id3);
  147. +                /* copy_mp3entry(&lasttrack_id3, &id3); */
  148.                  goto buffer_full;
  149.              }
  150.  
  151. -            if (track_widx == track_ridx)
  152. -                copy_mp3entry(&curtrack_id3, &id3);
  153. +            if (start_play)
  154. +                buf_request_buffer_handle(tracks[track_widx].id3_hid);
  155. +
  156. +            if (track_widx == track_ridx) {
  157. +                copy_mp3entry(&curtrack_id3, bufgetid3(tracks[track_widx].id3_hid));
  158. +                curtrack_id3.offset = offset;
  159. +            }
  160.  
  161.              if (start_play)
  162.              {
  163.                  track_changed = true;
  164.                  playlist_update_resume_info(audio_current_track());
  165.              }
  166. -        }
  167. -        else
  168. -        {
  169. -            logf("mde:%s!",trackname);
  170. -
  171. -            /* Skip invalid entry from playlist. */
  172. -            playlist_skip_entry(NULL, last_peek_offset);
  173. -            close(fd);
  174. -            goto peek_again;
  175. -        }
  176.  
  177.      }
  178.  
  179.      close(fd);
  180.  
  181. +    return true;
  182. +
  183. +buffer_full:
  184. +    logf("buffer is full for now");
  185. +    filling = STATE_FULL;
  186. +    return false;
  187. +}
  188. +
  189. +static bool audio_finish_load_track(void)
  190. +{
  191. +    char msgbuf[80];
  192. +    int file_offset = 0;
  193. +    bool start_play = track_widx == track_ridx;
  194. +    int offset = 0;
  195. +
  196.  #if 0
  197.      if (cuesheet_is_enabled() && tracks[track_widx].id3.cuesheet_type == 1)
  198.      {
  199. @@ -1678,6 +1689,9 @@ static bool audio_load_track(int offset, bool start_play)
  200.      }
  201.  #endif
  202.  
  203. +    if (tracks[track_widx].id3_hid < 0)
  204. +        return false;
  205. +
  206.      struct mp3entry *track_id3;
  207.  
  208.      if (track_widx == track_ridx)
  209. @@ -1700,20 +1714,21 @@ static bool audio_load_track(int offset, bool start_play)
  210.          if (tracks[track_widx].codec_hid == ERR_BUFFER_FULL)
  211.          {
  212.              /* No space for codec on buffer, not an error */
  213. -            goto buffer_full;
  214. +            return false;
  215.          }
  216.  
  217.          /* This is an error condition, either no codec was found, or reading
  218.           * the codec file failed part way through, either way, skip the track */
  219. -        snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", trackname);
  220. +        snprintf(msgbuf, sizeof(msgbuf)-1, "No codec for: %s", track_id3->path);
  221.          /* We should not use gui_syncplash from audio thread! */
  222.          gui_syncsplash(HZ*2, msgbuf);
  223.          /* Skip invalid entry from playlist. */
  224.          playlist_skip_entry(NULL, last_peek_offset);
  225. -        goto peek_again;
  226. +        return false;
  227.      }
  228.  
  229.      track_id3->elapsed = 0;
  230. +    offset = track_id3->offset;
  231.  
  232.      enum data_type type = TYPE_PACKET_AUDIO;
  233.  
  234. @@ -1755,7 +1770,7 @@ static bool audio_load_track(int offset, bool start_play)
  235.          break;
  236.      }
  237.  
  238. -    logf("alt:%s", trackname);
  239. +    logf("alt:%s", track_id3->path);
  240.  
  241.      if (file_offset > AUDIO_REBUFFER_GUESS_SIZE)
  242.          file_offset -= AUDIO_REBUFFER_GUESS_SIZE;
  243. @@ -1764,10 +1779,10 @@ static bool audio_load_track(int offset, bool start_play)
  244.      else
  245.          file_offset = 0;
  246.  
  247. -    tracks[track_widx].audio_hid = bufopen(trackname, file_offset, type);
  248. +    tracks[track_widx].audio_hid = bufopen(track_id3->path, file_offset, type);
  249.  
  250.      if (tracks[track_widx].audio_hid < 0)
  251. -        goto buffer_full;
  252. +        return false;
  253.  
  254.      /* All required data is now available for the codec. */
  255.      tracks[track_widx].taginfo_ready = true;
  256. @@ -1780,12 +1795,11 @@ static bool audio_load_track(int offset, bool start_play)
  257.  
  258.      track_widx = (track_widx + 1) & MAX_TRACK_MASK;
  259.  
  260. -    return true;
  261. +    /* load next track */
  262. +    LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");
  263. +    queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);
  264.  
  265. -buffer_full:
  266. -    logf("buffer is full for now");
  267. -    filling = STATE_FULL;
  268. -    return false;
  269. +    return true;
  270.  }
  271.  
  272.  static void audio_fill_file_buffer(bool start_play, size_t offset)
  273. @@ -1815,6 +1829,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  274.      playlist_update_resume_info(audio_current_track());
  275.  
  276.      continue_buffering = audio_load_track(offset, start_play);
  277. +#if 0
  278.      do {
  279.          sleep(1);
  280.          if (!queue_empty(&audio_queue))
  281. @@ -1822,6 +1837,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset)
  282.              break;
  283.          continue_buffering = audio_load_track(0, false);
  284.      } while (continue_buffering);
  285. +#endif
  286.  
  287.      if (!had_next_track && audio_next_track())
  288.          track_changed = true;
  289. @@ -2196,22 +2212,22 @@ static void audio_finalise_track_change(void)
  290.      {
  291.          wps_offset = 0;
  292.          automatic_skip = false;
  293. -    }
  294.  
  295. -    /* Invalidate prevtrack_id3 */
  296. -    prevtrack_id3.path[0] = 0;
  297. +        /* Invalidate prevtrack_id3 */
  298. +        prevtrack_id3.path[0] = 0;
  299.  
  300. -    if (prev_ti && prev_ti->audio_hid < 0)
  301. -    {
  302. -        /* No audio left so we clear all the track info. */
  303. -        clear_track_info(prev_ti);
  304. -    }
  305. +        if (prev_ti && prev_ti->audio_hid < 0)
  306. +        {
  307. +            /* No audio left so we clear all the track info. */
  308. +            clear_track_info(prev_ti);
  309. +        }
  310.  
  311. -    if (prev_ti && prev_ti->id3_hid >= 0)
  312. -    {
  313. -        /* Reset the elapsed time to force the progressbar to be empty if
  314. -           the user skips back to this track */
  315. -        bufgetid3(prev_ti->id3_hid)->elapsed = 0;
  316. +        if (prev_ti && prev_ti->id3_hid >= 0)
  317. +        {
  318. +            /* Reset the elapsed time to force the progressbar to be empty if
  319. +            the user skips back to this track */
  320. +            bufgetid3(prev_ti->id3_hid)->elapsed = 0;
  321. +        }
  322.      }
  323.  
  324.      send_event(PLAYBACK_EVENT_TRACK_CHANGE, &curtrack_id3);
  325. @@ -2298,6 +2314,11 @@ static void audio_thread(void)
  326.                  audio_fill_file_buffer(false, 0);
  327.                  break;
  328.  
  329. +            case Q_AUDIO_FINISH_LOAD:
  330. +                LOGFQUEUE("audio < Q_AUDIO_FINISH_LOAD");
  331. +                audio_finish_load_track();
  332. +                break;
  333. +
  334.              case Q_AUDIO_PLAY:
  335.                  LOGFQUEUE("audio < Q_AUDIO_PLAY");
  336.                  if (playing && ev.data <= 0)
  337. @@ -2397,8 +2418,8 @@ static void audio_thread(void)
  338.  
  339.              case SYS_TIMEOUT:
  340.                  LOGFQUEUE_SYS_TIMEOUT("audio < SYS_TIMEOUT");
  341. -                if (filling == STATE_FILLING)
  342. -                    audio_fill_file_buffer(false, 0);
  343. +                /* if (filling == STATE_FILLING)
  344. +                    audio_fill_file_buffer(false, 0); */
  345.                  break;
  346.  
  347.              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