mirror of
				https://github.com/nyanmisaka/ffmpeg-rockchip.git
				synced 2025-10-31 20:42:49 +08:00 
			
		
		
		
	add ff_index_search_timestamp and ff_add_index_entry
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit e6fb5a4f78)
			
			
This commit is contained in:
		 Peter Ross
					Peter Ross
				
			
				
					committed by
					
						 Michael Niedermayer
						Michael Niedermayer
					
				
			
			
				
	
			
			
			 Michael Niedermayer
						Michael Niedermayer
					
				
			
						parent
						
							566f17b62d
						
					
				
				
					commit
					2d9fd1810b
				
			| @@ -226,4 +226,18 @@ void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf, | |||||||
|  */ |  */ | ||||||
| int ff_find_stream_index(AVFormatContext *s, int id); | int ff_find_stream_index(AVFormatContext *s, int id); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Internal version of av_index_search_timestamp | ||||||
|  |  */ | ||||||
|  | int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, | ||||||
|  |                               int64_t wanted_timestamp, int flags); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Internal version of av_add_index_entry | ||||||
|  |  */ | ||||||
|  | int ff_add_index_entry(AVIndexEntry **index_entries, | ||||||
|  |                        int *nb_index_entries, | ||||||
|  |                        unsigned int *index_entries_allocated_size, | ||||||
|  |                        int64_t pos, int64_t timestamp, int size, int distance, int flags); | ||||||
|  |  | ||||||
| #endif /* AVFORMAT_INTERNAL_H */ | #endif /* AVFORMAT_INTERNAL_H */ | ||||||
|   | |||||||
| @@ -1370,28 +1370,30 @@ void ff_reduce_index(AVFormatContext *s, int stream_index) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| int av_add_index_entry(AVStream *st, | int ff_add_index_entry(AVIndexEntry **index_entries, | ||||||
|                             int64_t pos, int64_t timestamp, int size, int distance, int flags) |                        int *nb_index_entries, | ||||||
|  |                        unsigned int *index_entries_allocated_size, | ||||||
|  |                        int64_t pos, int64_t timestamp, int size, int distance, int flags) | ||||||
| { | { | ||||||
|     AVIndexEntry *entries, *ie; |     AVIndexEntry *entries, *ie; | ||||||
|     int index; |     int index; | ||||||
|  |  | ||||||
|     if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) |     if((unsigned)*nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
|     entries = av_fast_realloc(st->index_entries, |     entries = av_fast_realloc(*index_entries, | ||||||
|                               &st->index_entries_allocated_size, |                               index_entries_allocated_size, | ||||||
|                               (st->nb_index_entries + 1) * |                               (*nb_index_entries + 1) * | ||||||
|                               sizeof(AVIndexEntry)); |                               sizeof(AVIndexEntry)); | ||||||
|     if(!entries) |     if(!entries) | ||||||
|         return -1; |         return -1; | ||||||
|  |  | ||||||
|     st->index_entries= entries; |     *index_entries= entries; | ||||||
|  |  | ||||||
|     index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY); |     index= ff_index_search_timestamp(*index_entries, *nb_index_entries, timestamp, AVSEEK_FLAG_ANY); | ||||||
|  |  | ||||||
|     if(index<0){ |     if(index<0){ | ||||||
|         index= st->nb_index_entries++; |         index= (*nb_index_entries)++; | ||||||
|         ie= &entries[index]; |         ie= &entries[index]; | ||||||
|         assert(index==0 || ie[-1].timestamp < timestamp); |         assert(index==0 || ie[-1].timestamp < timestamp); | ||||||
|     }else{ |     }else{ | ||||||
| @@ -1399,8 +1401,8 @@ int av_add_index_entry(AVStream *st, | |||||||
|         if(ie->timestamp != timestamp){ |         if(ie->timestamp != timestamp){ | ||||||
|             if(ie->timestamp <= timestamp) |             if(ie->timestamp <= timestamp) | ||||||
|                 return -1; |                 return -1; | ||||||
|             memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index)); |             memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(*nb_index_entries - index)); | ||||||
|             st->nb_index_entries++; |             (*nb_index_entries)++; | ||||||
|         }else if(ie->pos == pos && distance < ie->min_distance) //do not reduce the distance |         }else if(ie->pos == pos && distance < ie->min_distance) //do not reduce the distance | ||||||
|             distance= ie->min_distance; |             distance= ie->min_distance; | ||||||
|     } |     } | ||||||
| @@ -1414,11 +1416,17 @@ int av_add_index_entry(AVStream *st, | |||||||
|     return index; |     return index; | ||||||
| } | } | ||||||
|  |  | ||||||
| int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, | int av_add_index_entry(AVStream *st, | ||||||
|                               int flags) |                        int64_t pos, int64_t timestamp, int size, int distance, int flags) | ||||||
|  | { | ||||||
|  |     return ff_add_index_entry(&st->index_entries, &st->nb_index_entries, | ||||||
|  |                               &st->index_entries_allocated_size, pos, | ||||||
|  |                               timestamp, size, distance, flags); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, | ||||||
|  |                               int64_t wanted_timestamp, int flags) | ||||||
| { | { | ||||||
|     AVIndexEntry *entries= st->index_entries; |  | ||||||
|     int nb_entries= st->nb_index_entries; |  | ||||||
|     int a, b, m; |     int a, b, m; | ||||||
|     int64_t timestamp; |     int64_t timestamp; | ||||||
|  |  | ||||||
| @@ -1450,6 +1458,13 @@ int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, | |||||||
|     return  m; |     return  m; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, | ||||||
|  |                               int flags) | ||||||
|  | { | ||||||
|  |     return ff_index_search_timestamp(st->index_entries, st->nb_index_entries, | ||||||
|  |                                      wanted_timestamp, flags); | ||||||
|  | } | ||||||
|  |  | ||||||
| #define DEBUG_SEEK | #define DEBUG_SEEK | ||||||
|  |  | ||||||
| int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ | int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ | |||||||
| #include "libavutil/intreadwrite.h" | #include "libavutil/intreadwrite.h" | ||||||
| #include "libavutil/intfloat_readwrite.h" | #include "libavutil/intfloat_readwrite.h" | ||||||
| #include "avformat.h" | #include "avformat.h" | ||||||
|  | #include "internal.h" | ||||||
| #include "riff.h" | #include "riff.h" | ||||||
| #include "asf.h" | #include "asf.h" | ||||||
| #include "mpegts.h" | #include "mpegts.h" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user