154 or=or->next; |
154 or=or->next; |
155 } |
155 } |
156 } |
156 } |
157 |
157 |
158 /* duplicate a reference (pointing to the same actual buffer memory) |
158 /* duplicate a reference (pointing to the same actual buffer memory) |
159 and increment buffer refcount. If the desired segment begins out |
159 and increment buffer refcount. If the desired segment is zero |
160 of range, NULL is returned; if the desired segment is simply zero |
160 length, a zero length ref is returned. */ |
161 length, a zero length ref is returned. Partial range overlap |
161 static ogg_reference *ogg_buffer_sub(ogg_reference *or,long length){ |
162 returns the overlap of the ranges */ |
|
163 static ogg_reference *ogg_buffer_sub(ogg_reference *or,long begin,long length){ |
|
164 ogg_reference *ret=0,*head=0; |
162 ogg_reference *ret=0,*head=0; |
165 |
163 |
166 /* walk past any preceeding fragments we don't want */ |
|
167 while(or && begin>=or->length){ |
|
168 begin-=or->length; |
|
169 or=or->next; |
|
170 } |
|
171 |
|
172 /* duplicate the reference chain; increment refcounts */ |
164 /* duplicate the reference chain; increment refcounts */ |
173 while(or && length){ |
165 while(or && length){ |
174 ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner); |
166 ogg_reference *temp=_fetch_ref(or->buffer->ptr.owner); |
175 if(head) |
167 if(head) |
176 head->next=temp; |
168 head->next=temp; |
177 else |
169 else |
178 ret=temp; |
170 ret=temp; |
179 head=temp; |
171 head=temp; |
180 head->buffer=or->buffer; |
172 head->buffer=or->buffer; |
181 head->begin=or->begin+begin; |
173 head->begin=or->begin; |
182 head->length=length; |
174 head->length=length; |
183 if(head->length>or->length-begin) |
175 if(head->length>or->length) |
184 head->length=or->length-begin; |
176 head->length=or->length; |
185 |
177 |
186 begin=0; |
|
187 length-=head->length; |
178 length-=head->length; |
188 or=or->next; |
179 or=or->next; |
189 } |
180 } |
190 |
181 |
191 ogg_buffer_mark(ret); |
182 ogg_buffer_mark(ret); |
425 |
416 |
426 /* Now we get to the actual framing code */ |
417 /* Now we get to the actual framing code */ |
427 |
418 |
428 int ogg_page_version(ogg_page *og){ |
419 int ogg_page_version(ogg_page *og){ |
429 oggbyte_buffer ob; |
420 oggbyte_buffer ob; |
430 oggbyte_init(&ob,og->header); |
421 if(oggbyte_init(&ob,og->header))return -1; |
431 return oggbyte_read1(&ob,4); |
422 return oggbyte_read1(&ob,4); |
432 } |
423 } |
433 |
424 |
434 int ogg_page_continued(ogg_page *og){ |
425 int ogg_page_continued(ogg_page *og){ |
435 oggbyte_buffer ob; |
426 oggbyte_buffer ob; |
436 oggbyte_init(&ob,og->header); |
427 if(oggbyte_init(&ob,og->header))return -1; |
437 return oggbyte_read1(&ob,5)&0x01; |
428 return oggbyte_read1(&ob,5)&0x01; |
438 } |
429 } |
439 |
430 |
440 int ogg_page_bos(ogg_page *og){ |
431 int ogg_page_bos(ogg_page *og){ |
441 oggbyte_buffer ob; |
432 oggbyte_buffer ob; |
442 oggbyte_init(&ob,og->header); |
433 if(oggbyte_init(&ob,og->header))return -1; |
443 return oggbyte_read1(&ob,5)&0x02; |
434 return oggbyte_read1(&ob,5)&0x02; |
444 } |
435 } |
445 |
436 |
446 int ogg_page_eos(ogg_page *og){ |
437 int ogg_page_eos(ogg_page *og){ |
447 oggbyte_buffer ob; |
438 oggbyte_buffer ob; |
448 oggbyte_init(&ob,og->header); |
439 if(oggbyte_init(&ob,og->header))return -1; |
449 return oggbyte_read1(&ob,5)&0x04; |
440 return oggbyte_read1(&ob,5)&0x04; |
450 } |
441 } |
451 |
442 |
452 ogg_int64_t ogg_page_granulepos(ogg_page *og){ |
443 ogg_int64_t ogg_page_granulepos(ogg_page *og){ |
453 oggbyte_buffer ob; |
444 oggbyte_buffer ob; |
454 oggbyte_init(&ob,og->header); |
445 if(oggbyte_init(&ob,og->header))return -1; |
455 return oggbyte_read8(&ob,6); |
446 return oggbyte_read8(&ob,6); |
456 } |
447 } |
457 |
448 |
458 ogg_uint32_t ogg_page_serialno(ogg_page *og){ |
449 ogg_uint32_t ogg_page_serialno(ogg_page *og){ |
459 oggbyte_buffer ob; |
450 oggbyte_buffer ob; |
460 oggbyte_init(&ob,og->header); |
451 if(oggbyte_init(&ob,og->header)) return 0xffffffffUL; |
461 return oggbyte_read4(&ob,14); |
452 return oggbyte_read4(&ob,14); |
462 } |
453 } |
463 |
454 |
464 ogg_uint32_t ogg_page_pageno(ogg_page *og){ |
455 ogg_uint32_t ogg_page_pageno(ogg_page *og){ |
465 oggbyte_buffer ob; |
456 oggbyte_buffer ob; |
466 oggbyte_init(&ob,og->header); |
457 if(oggbyte_init(&ob,og->header))return 0xffffffffUL; |
467 return oggbyte_read4(&ob,18); |
458 return oggbyte_read4(&ob,18); |
468 } |
459 } |
469 |
460 |
470 /* returns the number of packets that are completed on this page (if |
461 /* returns the number of packets that are completed on this page (if |
471 the leading packet is begun on a previous page, but ends on this |
462 the leading packet is begun on a previous page, but ends on this |