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