summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/mpegplayer/mpegplayer.c105
1 files changed, 84 insertions, 21 deletions
diff --git a/apps/plugins/mpegplayer/mpegplayer.c b/apps/plugins/mpegplayer/mpegplayer.c
index b5e11980db..dbbdc2317f 100644
--- a/apps/plugins/mpegplayer/mpegplayer.c
+++ b/apps/plugins/mpegplayer/mpegplayer.c
@@ -380,9 +380,12 @@ static int video_thumb_print IBSS_ATTR; /* If 1, the video thread is
380 only decoding one frame for 380 only decoding one frame for
381 use in the menu. If 0, 381 use in the menu. If 0,
382 normal operation */ 382 normal operation */
383static int play_time IBSS_ATTR; /* The movie time as represented by 383static int end_pts_time IBSS_ATTR; /* The movie end time as represented by
384 the maximum audio PTS tag in the 384 the maximum audio PTS tag in the
385 stream converted to half minutes */ 385 stream converted to half minutes */
386static int start_pts_time IBSS_ATTR; /* The movie start time as represented by
387 the first audio PTS tag in the
388 stream converted to half minutes */
386char *filename; /* hack for resume time storage */ 389char *filename; /* hack for resume time storage */
387 390
388 391
@@ -1116,7 +1119,8 @@ static int button_loop(void)
1116 rb->lcd_setfont(FONT_SYSFIXED); 1119 rb->lcd_setfont(FONT_SYSFIXED);
1117 1120
1118 if (result) { 1121 if (result) {
1119 settings.resume_time = (int)(get_stream_time()/44100/30); 1122 settings.resume_time = (int)(get_stream_time()/44100/
1123 30-start_pts_time);
1120 str_send_msg(&video_str, STREAM_QUIT, 0); 1124 str_send_msg(&video_str, STREAM_QUIT, 0);
1121 audio_str.status = STREAM_STOPPED; 1125 audio_str.status = STREAM_STOPPED;
1122 } else { 1126 } else {
@@ -1127,12 +1131,16 @@ static int button_loop(void)
1127 break; 1131 break;
1128 1132
1129 case MPEG_STOP: 1133 case MPEG_STOP:
1130 settings.resume_time = (int)(get_stream_time()/44100/30); 1134 settings.resume_time = (int)(get_stream_time()/44100/
1135 30-start_pts_time);
1131 str_send_msg(&video_str, STREAM_QUIT, 0); 1136 str_send_msg(&video_str, STREAM_QUIT, 0);
1132 audio_str.status = STREAM_STOPPED; 1137 audio_str.status = STREAM_STOPPED;
1133 break; 1138 break;
1134 1139
1135 case MPEG_PAUSE: 1140 case MPEG_PAUSE:
1141 settings.resume_time = (int)(get_stream_time()/44100/
1142 30-start_pts_time);
1143 save_settings();
1136 str_send_msg(&video_str, STREAM_PAUSE, 0); 1144 str_send_msg(&video_str, STREAM_PAUSE, 0);
1137 audio_str.status = STREAM_PAUSED; 1145 audio_str.status = STREAM_PAUSED;
1138 pcm_playback_play_pause(false); 1146 pcm_playback_play_pause(false);
@@ -1937,13 +1945,59 @@ void display_thumb(int in_file)
1937 rb->splash(0, "frame not available"); 1945 rb->splash(0, "frame not available");
1938} 1946}
1939 1947
1940int find_length( int in_file ) 1948int find_start_pts( int in_file )
1949{
1950 uint8_t *p;
1951 size_t read_length = 60*1024;
1952 size_t disk_buf_len;
1953
1954 start_pts_time = 0;
1955
1956 /* temporary read buffer size cannot exceed buffer size */
1957 if ( read_length > disk_buf_size )
1958 read_length = disk_buf_size;
1959
1960 /* read tail of file */
1961 rb->lseek( in_file, 0, SEEK_SET );
1962 disk_buf_len = rb->read( in_file, disk_buf_start, read_length );
1963 disk_buf_tail = disk_buf_start + disk_buf_len;
1964
1965 /* sync reader to this segment of the stream */
1966 p=disk_buf_start;
1967 if (sync_data_stream(&p))
1968 {
1969 DEBUGF("Could not sync stream\n");
1970 return PLUGIN_ERROR;
1971 }
1972
1973 /* find first PTS in audio stream. if the PTS can not be determined,
1974 set start_pts_time to 0 */
1975 audio_sync_start = 0;
1976 audio_sync_time = 0;
1977 video_sync_start = 0;
1978 {
1979 Stream tmp;
1980 initialize_stream(&tmp,p,disk_buf_len-(disk_buf_start-p),0xc0);
1981 int count=0;
1982 do
1983 {
1984 count++;
1985 get_next_data(&tmp, 2);
1986 }
1987 while (tmp.tagged != 1 && count < 30);
1988 if (tmp.tagged == 1)
1989 start_pts_time = (int)((tmp.curr_pts/45000)/30);
1990 }
1991 return 0;
1992}
1993
1994int find_end_pts( int in_file )
1941{ 1995{
1942 uint8_t *p; 1996 uint8_t *p;
1943 size_t read_length = 60*1024; 1997 size_t read_length = 60*1024;
1944 size_t disk_buf_len; 1998 size_t disk_buf_len;
1945 1999
1946 play_time = 0; 2000 end_pts_time = 0;
1947 2001
1948 /* temporary read buffer size cannot exceed buffer size */ 2002 /* temporary read buffer size cannot exceed buffer size */
1949 if ( read_length > disk_buf_size ) 2003 if ( read_length > disk_buf_size )
@@ -1963,7 +2017,7 @@ int find_length( int in_file )
1963 } 2017 }
1964 2018
1965 /* find last PTS in audio stream; will movie always have audio? if 2019 /* find last PTS in audio stream; will movie always have audio? if
1966 the play time can not be determined, set play_time to 0 */ 2020 the play time can not be determined, set end_pts_time to 0 */
1967 audio_sync_start = 0; 2021 audio_sync_start = 0;
1968 audio_sync_time = 0; 2022 audio_sync_time = 0;
1969 video_sync_start = 0; 2023 video_sync_start = 0;
@@ -1976,7 +2030,7 @@ int find_length( int in_file )
1976 get_next_data(&tmp, 2); 2030 get_next_data(&tmp, 2);
1977 if (tmp.tagged == 1) 2031 if (tmp.tagged == 1)
1978 /* 10 sec less to insure the video frame exist */ 2032 /* 10 sec less to insure the video frame exist */
1979 play_time = (int)((tmp.curr_pts/45000-10)/30); 2033 end_pts_time = (int)((tmp.curr_pts/45000-10)/30);
1980 } 2034 }
1981 while (tmp.curr_packet_end != NULL); 2035 while (tmp.curr_packet_end != NULL);
1982 } 2036 }
@@ -2003,8 +2057,10 @@ ssize_t seek_PTS( int in_file, int start_time, int accept_button )
2003 } 2057 }
2004 else if ( start_time != 0 ) 2058 else if ( start_time != 0 )
2005 { 2059 {
2006 seek_pos = rb->filesize(in_file)*start_time/play_time; 2060 seek_pos = rb->filesize(in_file)*start_time/
2007 int seek_pos_sec_inc = rb->filesize(in_file)/play_time/30; 2061 (end_pts_time-start_pts_time);
2062 int seek_pos_sec_inc = rb->filesize(in_file)/
2063 (end_pts_time-start_pts_time)/30;
2008 2064
2009 if (seek_pos<0) 2065 if (seek_pos<0)
2010 seek_pos=0; 2066 seek_pos=0;
@@ -2058,9 +2114,11 @@ ssize_t seek_PTS( int in_file, int start_time, int accept_button )
2058 } 2114 }
2059 2115
2060 /* are we after start_time in the stream? */ 2116 /* are we after start_time in the stream? */
2061 if ( coarse_seek && (int)(tmp.curr_pts/45000) >= start_time*30 ) 2117 if ( coarse_seek && (int)(tmp.curr_pts/45000) >=
2118 (start_time+start_pts_time)*30 )
2062 { 2119 {
2063 int time_to_backup = (int)(tmp.curr_pts/45000) - start_time*30; 2120 int time_to_backup = (int)(tmp.curr_pts/45000) -
2121 (start_time+start_pts_time)*30;
2064 if (time_to_backup == 0) 2122 if (time_to_backup == 0)
2065 time_to_backup++; 2123 time_to_backup++;
2066 seek_pos -= seek_pos_sec_inc * time_to_backup; 2124 seek_pos -= seek_pos_sec_inc * time_to_backup;
@@ -2085,9 +2143,11 @@ ssize_t seek_PTS( int in_file, int start_time, int accept_button )
2085 } 2143 }
2086 2144
2087 /* are we well before start_time in the stream? */ 2145 /* are we well before start_time in the stream? */
2088 if ( coarse_seek && start_time*30 - (int)(tmp.curr_pts/45000) > 2 ) 2146 if ( coarse_seek && (start_time+start_pts_time)*30 -
2147 (int)(tmp.curr_pts/45000) > 2 )
2089 { 2148 {
2090 int time_to_advance = start_time*30 - (int)(tmp.curr_pts/45000) - 2; 2149 int time_to_advance = (start_time+start_pts_time)*30 -
2150 (int)(tmp.curr_pts/45000) - 2;
2091 if (time_to_advance <= 0) 2151 if (time_to_advance <= 0)
2092 time_to_advance = 1; 2152 time_to_advance = 1;
2093 seek_pos += seek_pos_sec_inc * time_to_advance; 2153 seek_pos += seek_pos_sec_inc * time_to_advance;
@@ -2113,14 +2173,16 @@ ssize_t seek_PTS( int in_file, int start_time, int accept_button )
2113 coarse_seek = 0; 2173 coarse_seek = 0;
2114 2174
2115 /* are we at start_time in the stream? */ 2175 /* are we at start_time in the stream? */
2116 if ( (int)(tmp.curr_pts/45000) >= start_time*30 ) 2176 if ( (int)(tmp.curr_pts/45000) >= (start_time+start_pts_time)*
2177 30 )
2117 cont_seek_loop = 0; 2178 cont_seek_loop = 0;
2118 2179
2119 } 2180 }
2120 while ( cont_seek_loop ); 2181 while ( cont_seek_loop );
2121 2182
2122 2183
2123 DEBUGF("start diff: %u %u\n",(unsigned int)(tmp.curr_pts/45000),start_time*30); 2184 DEBUGF("start diff: %u %u\n",(unsigned int)(tmp.curr_pts/45000),
2185 (start_time+start_pts_time)*30);
2124 seek_pos+=tmp.curr_packet_end-disk_buf_start; 2186 seek_pos+=tmp.curr_packet_end-disk_buf_start;
2125 2187
2126 last_seek_pos = seek_pos; 2188 last_seek_pos = seek_pos;
@@ -2257,18 +2319,19 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2257 2319
2258 disk_buf_end = disk_buf_start + disk_buf_size-MPEG_GUARDBUF_SIZE; 2320 disk_buf_end = disk_buf_start + disk_buf_size-MPEG_GUARDBUF_SIZE;
2259 2321
2260 /* initalize play_time with the length (in half minutes) of the movie 2322 /* initalize start_pts_time and end_pts_time with the length (in half
2261 zero if the time could not be determined */ 2323 minutes) of the movie. zero if the time could not be determined */
2262 find_length( in_file ); 2324 find_start_pts( in_file );
2325 find_end_pts( in_file );
2263 2326
2264 /* start menu */ 2327 /* start menu */
2265 start_time = mpeg_start_menu(play_time, in_file); 2328 start_time = mpeg_start_menu(end_pts_time-start_pts_time, in_file);
2266 if ( start_time == -1 ) 2329 if ( start_time == -1 )
2267 return 0; 2330 return 0;
2268 else if ( start_time < 0 ) 2331 else if ( start_time < 0 )
2269 start_time = 0; 2332 start_time = 0;
2270 else if ( start_time > play_time ) 2333 else if ( start_time > (end_pts_time-start_pts_time) )
2271 start_time = play_time; 2334 start_time = (end_pts_time-start_pts_time);
2272 2335
2273 rb->splash(0, "loading ..."); 2336 rb->splash(0, "loading ...");
2274 2337