Index: apps/codecs/cook.c
===================================================================
--- apps/codecs/cook.c	(revision 21720)
+++ apps/codecs/cook.c	(working copy)
@@ -86,56 +86,54 @@
     ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE);

     /* The main decoder loop */  
-    while (1)
-   {
-        /*if (ci->seek_time) {
+seek_start :         
+    while(packet_count)
+    {  
+        bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
+        consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
+        if(consumed < 0) {
+            DEBUGF("rm_get_packet failed\n");
+            return CODEC_ERROR;
+        }
+        /*DEBUGF("    version = %d\n"
+                 "    length  = %d\n"
+                 "    stream  = %d\n"
+                 "    timestamp= %d\n",pkt.version,pkt.length,pkt.stream_number,pkt.timestamp);*/

-            ci->set_elapsed(ci->seek_time);
-            n = ci->seek_time/10;
-            memset(buf,0,BUF_SIZE);              
-            ci->seek_complete();            
-        }*/
-         
-        while(packet_count)
-        {  
-            bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size);
-            consumed = rm_get_packet(&bit_buffer, &rmctx, &pkt);
-            if(consumed < 0) {
-                DEBUGF("rm_get_packet failed\n");
-                return CODEC_ERROR;
-            }
-            /*DEBUGF("    version = %d\n"
-                     "    length  = %d\n"
-                     "    stream  = %d\n"
-                     "    timestamp= %d\n",pkt.version,pkt.length,pkt.stream_number,pkt.timestamp);*/
+        for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
+        { 
+            ci->yield();
+            if (ci->stop_codec || ci->new_track)
+                goto done;
+             if (ci->seek_time == 1) {
+                ci->seek_buffer(rmctx.data_offset + DATA_HEADER_SIZE);
+                ci->set_elapsed(0);
+                packet_count = rmctx.nb_packets;
+                rmctx.audio_pkt_cnt = 0;
+                rmctx.frame_number = 0;
+                ci->seek_complete();
+                goto seek_start;           
+             }

-            for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++)
-            { 
-                ci->yield();
-                if (ci->stop_codec || ci->new_track)
-                    goto done;
+            res = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align);
+            rmctx.frame_number++;

-                res = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align);
-                rmctx.frame_number++;
+            /* skip the first two frames; no valid audio */
+            if(rmctx.frame_number < 3) continue;

-                /* skip the first two frames; no valid audio */
-                if(rmctx.frame_number < 3) continue;
-
-                if(res != rmctx.block_align) {
-                    DEBUGF("codec error\n");
-                    return CODEC_ERROR;
-                }
-
-                ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels);
-                ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i);       
+            if(res != rmctx.block_align) {
+                DEBUGF("codec error\n");
+                return CODEC_ERROR;
             }
-            packet_count -= rmctx.audio_pkt_cnt;
-            rmctx.audio_pkt_cnt = 0;
-            ci->advance_buffer(consumed);
+
+            ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels);
+            ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i);       
         }
-        goto done;  
-        
+        packet_count -= rmctx.audio_pkt_cnt;
+        rmctx.audio_pkt_cnt = 0;
+        ci->advance_buffer(consumed);
     }
+
     done :
     if (ci->request_next_track())
         goto next_track;