forked from vigith/Ogg-Theora-LibTheora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibTheora.xs
1273 lines (983 loc) · 25.5 KB
/
LibTheora.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include <ogg/ogg.h>
#include <theora/codec.h>
#include <theora/theora.h>
#include <theora/theoraenc.h>
#include <theora/theoradec.h>
#include "const-c.inc"
MODULE = Ogg::Theora::LibTheora PACKAGE = Ogg::Theora::LibTheora PREFIX = LibTheora_
INCLUDE: const-xs.inc
PROTOTYPES: DISABLE
=head1 Functions (malloc)
L<http://www.theora.org/doc/libtheora-1.0/annotated.html>
=cut
=head2 make_th_info
Creates a memory allocation for th_info.
-Input:
Void
-Output:
Memory Pointer
=cut
th_info *
LibTheora_make_th_info()
PREINIT:
th_info *memory;
CODE:
New(0, memory, 1, th_info);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_huff_code
Creates a memory allocation for th_huff_code.
-Input:
void
-Output:
Memory Pointer
=cut
th_huff_code *
LibTheora_make_th_huff_code()
PREINIT:
th_huff_code *memory;
CODE:
New(0, memory, 1, th_huff_code);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_img_plane
Creates a memory allocation for th_img_plane.
-Input:
void
-Output:
Memory Pointer
=cut
th_img_plane *
LibTheora_make_th_img_plane()
PREINIT:
th_img_plane *memory;
CODE:
New(0, memory, 1, th_img_plane);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_quant_info
Creates a memory allocation for th_quant_info.
-Input:
void
-Output:
Memory Pointer
=cut
th_quant_info *
LibTheora_make_th_quant_info()
PREINIT:
th_quant_info *memory;
CODE:
New(0, memory, 1, th_quant_info);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_quant_ranges
Creates a memory allocation for th_quant_ranges.
-Input:
void
-Output:
Memory Pointer
=cut
th_quant_ranges *
LibTheora_make_th_quant_ranges()
PREINIT:
th_quant_ranges *memory;
CODE:
New(0, memory, 1, th_quant_ranges);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_stripe_callback
Creates a memory allocation for th_stripe_callback.
-Input:
void
-Output:
Memory Pointer
=cut
th_stripe_callback *
LibTheora_make_th_stripe_callback()
PREINIT:
th_stripe_callback *memory;
CODE:
New(0, memory, 1, th_stripe_callback);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_ycbcr_buffer
Creates a memory allocation for th_ycbcr_buffer.
-Input:
void
-Output:
Memory Pointer
=cut
th_ycbcr_buffer *
LibTheora_make_th_ycbcr_buffer()
PREINIT:
th_ycbcr_buffer *memory;
CODE:
New(0, memory, 1, th_ycbcr_buffer);
RETVAL = memory;
OUTPUT:
RETVAL
=head2 make_th_comment
Creates a memory allocation for th_comment.
-Input:
void
-Output:
Memory Pointer
=cut
th_comment *
LibTheora_make_th_comment()
PREINIT:
th_comment *memory;
CODE:
New(0, memory, 1, th_comment);
RETVAL = memory;
OUTPUT:
RETVAL
=head1 Functions (Basic shared functions)
L<http://www.theora.org/doc/libtheora-1.0/group__basefuncs.html>
=cut
=head2 th_version_number
Retrieves the library version number.
-Input:
void
-Output:
ogg_uint32_t (IV)
=cut
ogg_uint32_t
LibTheora_th_version_number()
PREINIT:
ogg_uint32_t version;
CODE:
version = th_version_number();
RETVAL = version;
OUTPUT:
RETVAL
=head2 th_version_string
Retrieves a human-readable string to identify the library vendor and version.
-Input:
void
-Output:
const char * (T_PV)
=cut
const char *
LibTheora_th_version_string()
PREINIT:
const char *version;
CODE:
version = th_version_string();
RETVAL = version;
OUTPUT:
RETVAL
=head2 th_packet_isheader
Determines whether a Theora packet is a header or not.
-Input:
_op An ogg_packet containing encoded Theora data.
-Output:
1 packet is a header packet,
0 packet is a video data packet.
=cut
int
LibTheora_th_packet_isheader(_op)
ogg_packet * _op
CODE:
RETVAL = th_packet_isheader(_op);
OUTPUT:
RETVAL
=head2 th_granule_frame
Converts a granule position to an absolute frame index, starting at 0.
-Input:
void * _encdec (previously allocated th_enc_ctx or th_dec_ctx handle),
ogg_int64_t _granpos (granule position to convert).
-Output:
absolute frame index corresponding to _granpos,
-1 on error.
=cut
int
LibTheora_th_granule_frame(_encdec, _granpos)
void * _encdec
ogg_int64_t _granpos
CODE:
RETVAL = th_granule_frame(_encdec, _granpos);
OUTPUT:
RETVAL
=head2 th_granule_time
Converts a granule position to an absolute time in seconds.
-Input:
void * _encdec (previously allocated th_enc_ctx or th_dec_ctx handle),
ogg_int64_t _granpos (granule position to convert).
-Output:
absolute time in seconds corresponding to _granpos,
-1 on error.
=cut
double
LibTheora_th_granule_time(_encdec, _granpos)
void * _encdec
ogg_int64_t _granpos
CODE:
RETVAL = th_granule_time(_encdec, _granpos);
OUTPUT:
RETVAL
=head2 th_packet_iskeyframe
Determines whether a theora packet is a key frame or not.
-Input:
_op An ogg_packet containing encoded Theora data.
-Output:
1 packet is a key frame,
0 packet is a delta frame,
-1 packet is not a video data packet.
=cut
int
LibTheora_th_packet_iskeyframe(_op)
ogg_packet * _op
CODE:
RETVAL = th_packet_iskeyframe(_op);
OUTPUT:
RETVAL
=head1 Functions (Manipulating Header Data)
=cut
=head2 th_comment_init
Initialize a th_comment structure.
-Input:
th_comment *
-Output:
void
=cut
void
LibTheora_th_comment_init(_tc)
th_comment * _tc
CODE:
th_comment_init(_tc);
=head2 th_info_init
Initializes a th_info structure.
-Input:
th_info
-Output:
void
=cut
void
LibTheora_th_info_init(_info)
th_info * _info
CODE:
th_info_init(_info);
=head2 th_info_clear
Clears a th_info structure.
-Input:
th_info
-Output:
void
=cut
void
LibTheora_th_info_clear(_info)
th_info * _info
CODE:
th_info_clear(_info);
=head2 th_comment_add
Add a comment to an initialized th_comment structure.
-Input:
th_comment,
char * (null-terminated UTF-8 string containing the comment in "TAG=the value" form).
-Output:
void
=cut
void
LibTheora_th_comment_add(_tc, _comment)
th_comment * _tc
char * _comment
CODE:
int i;
th_comment_add(_tc, _comment);
=head2 th_comment_add_tag
Add a comment to an initialized th_comment structure.
-Input:
th_comment,
char * (null-terminated string containing the tag associated with the comment),
char * (corresponding value as a null-terminated string).
=cut
void
LibTheora_th_comment_add_tag(_tc, _tag, _val)
th_comment * _tc
char * _tag
char * _val
CODE:
th_comment_add_tag(_tc, _tag, _val);
=head2 th_comment_query_count
Look up the number of instances of a tag.
-Input:
th_comment,
char * (tag to look up).
-Output:
int (number on instances of this particular tag)
=cut
int
LibTheora_th_comment_query_count(_tc, _tag)
th_comment * _tc
char * _tag
CODE:
RETVAL = th_comment_query_count(_tc, _tag);
OUTPUT:
RETVAL
=head2 th_comment_query
Look up a comment value by its tag.
-Input:
th_comment,
char * (tag to look-up)
int (instance of the tag, it starts from 0)
-Output:
char * if matched pointer to the queried tag's value,
NULL if no matching tag is found
=cut
char *
LibTheora_th_comment_query(_tc, _tag, _count)
th_comment * _tc
char * _tag
int _count
CODE:
RETVAL = th_comment_query(_tc, _tag, _count);
OUTPUT:
RETVAL
=head1 Functions (For Decoding)
L<http://www.theora.org/doc/libtheora-1.0/group__decfuncs.html>
=cut
=head2 th_decode_headerin
Decodes the header packets of a Theora stream.
-Input:
th_info,
th_comment,
th_setup_info, (initialized to NULL on the first call & returned value be passed on subsequent calls)
ogg_packet
-Output:
0 first video data packet was encountered after all required header packets were parsed,
TH_EFAULT if one of _info, _tc, or _setup was NULL,
TH_EBADHEADER _op was NULL,
TH_EVERSION not decodable with current libtheoradec version,
TH_ENOTFORMAT not a Theora header
=cut
void
LibTheora_th_decode_headerin(_info, _tc, _setup_addr, _op)
th_info * _info
th_comment * _tc
int _setup_addr
ogg_packet * _op
PREINIT:
int status;
th_setup_info *_setup;
PPCODE:
_setup = (th_setup_info *) _setup_addr;
status = th_decode_headerin(_info, _tc, &_setup, _op);
XPUSHs(sv_2mortal(newSViv(status)));
XPUSHs(sv_2mortal(newSViv((unsigned int) _setup)));
=head2 th_decode_alloc
Allocates a decoder instance.
-Input:
th_info,
th_setup_info
-Output:
th_dec_ctx
=cut
th_dec_ctx *
LibTheora_th_decode_alloc(_info, _setup)
th_info * _info
int _setup
CODE:
RETVAL = th_decode_alloc(_info, (th_setup_info *) _setup);
OUTPUT:
RETVAL
=head2 th_setup_free
Releases all storage used for the decoder setup information.
-Input:
th_setup_info
-Output:
void
=cut
void
LibTheora_th_setup_free(_setup)
int _setup
CODE:
th_setup_free((th_setup_info *) _setup);
=head2 th_decode_packetin
Submits a packet containing encoded video data to the decoder.
-Input:
th_dec_ctx,
ogg_packet,
ogg_int64_t gran_pos, returns the granule position of the decoded packet
-Output:
0 success,
TH_DUPFRAME packet represented a dropped (0-byte) frame,
TH_EFAULT _dec or _op was NULL,
TH_EBADPACKET _op does not contain encoded video data,
TH_EIMPL video data uses bitstream features which this library does not support.
=cut
void
LibTheora_th_decode_packetin(_dec, _op, _granpos)
th_dec_ctx * _dec
ogg_packet * _op
unsigned int _granpos
PREINIT:
int status;
PPCODE:
status = th_decode_packetin(_dec, _op, (ogg_int64_t *) &_granpos);
XPUSHs(sv_2mortal(newSViv(status)));
XPUSHs(sv_2mortal(newSViv((unsigned int) _granpos)));
=head2 th_decode_ycbcr_out
Outputs the next available frame of decoded Y'CbCr data.
-Input:
th_dec_ctx,
th_ycbcr_buffer (video buffer structure to fill in)
-Output:
0 Success
=cut
int
LibTheora_th_decode_ycbcr_out(_dec, _ycbcr)
th_dec_ctx * _dec
th_ycbcr_buffer * _ycbcr
CODE:
RETVAL = th_decode_ycbcr_out(_dec, *_ycbcr);
OUTPUT:
RETVAL
=head2 th_decode_free
Frees an allocated decoder instance.
-Input:
th_dec_ctx
-Output:
void
=cut
void
LibTheora_th_decode_free(_dec)
th_dec_ctx * _dec
CODE:
th_decode_free(_dec);
=head2 th_decode_ctl
Decoder control function. (i haven't tested this)
-Input:
th_dec_ctx,
int _req (control code to process),
void * _buf (parameters for this control code),
size_t _buf_sz (size of the parameter buffer)
-Output:
int (not documented)
=cut
int
LibTheora_th_decode_ctl(_dec, _req, _buf, _buf_sz)
th_dec_ctx * _dec
int _req
void * _buf
size_t _buf_sz
CODE:
RETVAL = th_decode_ctl(_dec, _req, _buf, _buf_sz);
OUTPUT:
RETVAL
=head1 Functions (for Encoding)
L<http://www.theora.org/doc/libtheora-1.0/group__encfuncs.html>
=cut
=head2 th_encode_alloc
Allocates an encoder instance.
-Input:
th_info.
-Output:
th_enc_ctx handle,
NULL (if the encoding parameters were invalid).
=cut
th_enc_ctx *
LibTheora_th_encode_alloc(_info)
th_info * _info
CODE:
RETVAL = th_encode_alloc(_info);
OUTPUT:
RETVAL
=head2 th_encode_flushheader
-Input:
th_enc_ctx,
th_comment,
ogg_packet.
-Output:
> 1 (indicates that a header packet was successfully produced),
0 (no packet was produced, and no more header packets remain),
TH_EFAULT (_enc, _comments, or _op was NULL).
=cut
int
LibTheora_th_encode_flushheader(_enc, _comments, _op)
th_enc_ctx * _enc
th_comment * _comments
ogg_packet * _op
CODE:
RETVAL = th_encode_flushheader(_enc, _comments, _op);
OUTPUT:
RETVAL
=head2 th_encode_ycbcr_in
Submits an uncompressed frame to the encoder. (if you don't have ycbcr buffer
you can try using the *unoptimized* rgb_th_encode_ycbcr_in, better you write
your own).
-Input:
th_enc_ctx,
th_ycbcr_buffer
-Output:
0 Success,
TH_EFAULT _enc or _ycbcr is NULL,
TH_EINVAL buffer size does not match the frame size encoder was initialized.
=cut
int
LibTheora_th_encode_ycbcr_in(_enc, _ycbcr)
th_enc_ctx * _enc
th_ycbcr_buffer * _ycbcr
CODE:
RETVAL = th_encode_ycbcr_in(_enc, *_ycbcr);
OUTPUT:
RETVAL
=head2 th_encode_packetout
Retrieves encoded video data packets.
-Input:
th_enc_ctx,
int (non-zero value if no more uncompressed frames will be submitted),
ogg_packet.
-Output:
> 0 a video data packet was successfully produced,
0 no packet was produced, and no more encoded video data remains,
TH_EFAULT _enc or _op was NULL.
=cut
int
LibTheora_th_encode_packetout(_enc, _last, _op)
th_enc_ctx * _enc
int _last
ogg_packet * _op
CODE:
RETVAL = th_encode_packetout(_enc, _last, _op);
OUTPUT:
RETVAL
=head2 th_encode_free
Frees an allocated encoder instance.
-Input:
th_enc_ctx
-Output:
void
=cut
void
LibTheora_th_encode_free(_enc)
th_enc_ctx * _enc
CODE:
th_encode_free(_enc);
=head1 Miscellaneous Functions
These functions are not found in libtheora*, but is written by the XS author
to simplify few tasks.
=cut
=head2 get_th_info
Returns a HashRef with th_info struct values.
-Input:
th_info
-Output:
HashRef
=cut
HV *
LibTheora_get_th_info(_info)
th_info * _info
PREINIT:
HV * hash;
CODE:
hash = newHV();
sv_2mortal((SV *)hash); /* convert the HASH to a mortal */
hv_store(hash, "frame_width", strlen("frame_width"), newSVnv(_info->frame_width), 0);
hv_store(hash, "frame_height", strlen("frame_height"), newSVnv(_info->frame_height), 0);
hv_store(hash, "pic_width", strlen("pic_width"), newSVnv(_info->pic_width), 0);
hv_store(hash, "pic_height", strlen("pic_height"), newSVnv(_info->pic_height), 0);
hv_store(hash, "pic_x", strlen("pic_x"), newSVnv(_info->pic_x), 0);
hv_store(hash, "pic_y", strlen("pic_y"), newSVnv(_info->pic_y), 0);
hv_store(hash, "colorspace", strlen("colorspace"), newSVnv(_info->colorspace), 0);
hv_store(hash, "pixel_fmt", strlen("pixel_fmt"), newSVnv(_info->pixel_fmt), 0);
hv_store(hash, "target_bitrate", strlen("target_bitrate"), newSVnv(_info->target_bitrate), 0);
hv_store(hash, "quality", strlen("quality"), newSVnv(_info->quality), 0);
hv_store(hash, "version_major", strlen("version_major"), newSVnv(_info->version_major), 0);
hv_store(hash, "version_minor", strlen("version_minor"), newSVnv(_info->version_minor), 0);
hv_store(hash, "version_subminor", strlen("version_subminor"), newSVnv(_info->version_subminor), 0);
hv_store(hash, "fps_numerator", strlen("fps_numerator"), newSVnv(_info->fps_numerator), 0);
hv_store(hash, "fps_denominator", strlen("fps_denominator"), newSVnv(_info->fps_denominator), 0);
hv_store(hash, "aspect_numerator", strlen("aspect_numerator"), newSVnv(_info->aspect_numerator), 0);
hv_store(hash, "aspect_denominator", strlen("aspect_denominator"), newSVnv(_info->aspect_denominator), 0);
hv_store(hash, "keyframe_granule_shift", strlen("keyframe_granule_shift"), newSVnv(_info->keyframe_granule_shift), 0);
RETVAL = hash;
OUTPUT:
RETVAL
=head2 ycbcr_to_rgb_buffer
reads the data from the ycbcr buffer and converts to its equivalent
rgb buffer. (this is NOT an optimized code, there will be better ycbcr
to rgb convertors, some intel gpu processors have mnemonic that does
the conversion)
-Input:
th_ycbcr_buffer
-Output:
RGB string
=cut
SV *
LibTheora_ycbcr_to_rgb_buffer(_ycbcr)
th_ycbcr_buffer * _ycbcr;
PREINIT:
th_ycbcr_buffer buffer;
char *rgb;
long size, size1, size2, size3;
int i, i2, j, j2;
long pos, pos1, pos2;
int Y, U, V;
int R, G, B;
CODE:
memcpy(buffer,_ycbcr, sizeof(buffer));
size1 = buffer[0].width * buffer[0].height;
size2 = buffer[1].width * buffer[1].height;
size3 = buffer[2].width * buffer[2].height;
size = size1*3;
// this way, i don't have to worry about free'ing
RETVAL = newSV(size); // returns a pointer of type (SV *)
SvPOK_on(RETVAL);
// SvPV_nolen returns the pointer to array in RETVAL
rgb = (char *)SvPV_nolen(RETVAL);
// rgb == SvPV(RETVAL, size), i was curious :-)
for(i=0;i<buffer[0].height;i++) {
for(j=0;j<buffer[0].width;j++) {
i2 = (int) i/2;
j2 = (int) j/2;
pos = i*buffer[0].stride +j;
pos1 = i2*buffer[1].stride + j2;
pos2 = i2*buffer[2].stride + j2;
Y = (int) buffer[0].data[pos];
U = (int) buffer[1].data[pos1];
V = (int) buffer[2].data[pos2];
Y = Y - 128 - 16;
U = U - 128;
V = V - 128;
R = Y + 1.140*V;
G = Y - 0.395*U - 0.581*V;
B = Y + 2.032*U;
R += 128;
G += 128;
B += 128;
if (R > 255) R = 255;
if (R < 0) R = 0;
if (G > 255) G = 255;
if (G < 0) G = 0;
if (B > 255) B = 255;
if (B < 0) B = 0;
pos2 = (i*buffer[0].width+j)*3;
rgb[pos2] = R;
rgb[pos2+1] = G;
rgb[pos2+2] = B;
}
}
SvCUR_set(RETVAL, size);
OUTPUT:
RETVAL
=head2 get_th_comment
return an array of comments
-Input:
th_comment
-Output:
array of comments
=cut
void
LibTheora_get_th_comment(_tc)
th_comment * _tc
PREINIT:
int i = 0;
PPCODE:
EXTEND(SP, _tc->comments);
for(i=0; i < _tc->comments; i++) {
PUSHs((SV *)sv_2mortal(newSVpv(_tc->user_comments[i], strlen(_tc->user_comments[i]))));
}
=head2 set_th_info
sets the th_info structure to default values unless specified in hash. frame_width and frame_height
is mandatory.
-Input:
Hash of elements
-Output:
void
=cut
void
LibTheora_set_th_info(_info, hash)
th_info * _info
HV * hash
PREINIT:
char * key;
I32 klen;
SV *val;
int flag = 0;
int frame_width = 0;
int frame_height = 0;
int pic_width = 0;
int pic_height = 0;
int pic_x = 0;
int pic_y = 0;
int colorspace = TH_CS_ITU_REC_470M;
int pixel_fmt = TH_PF_420;
int quality = 0;
int keyframe_granule_shift = 6;
int target_bitrate = 0;
int aspect_denominator = 1;
int aspect_numerator = 1;
int fps_numerator = 25000;
int fps_denominator = 1000;
CODE:
/* get the values from the hash and override the defaults */
(void)hv_iterinit(hash);
while ((val = hv_iternextsv(hash, (char **) &key, &klen))) {
if (strEQ(key, "frame_width")) {
frame_width = SvIV(val);
flag++;
continue;
}
if (strEQ(key, "frame_height")) {
frame_height = SvIV(val);
flag++;
continue;
}
if (strEQ(key, "pic_width")) {
pic_width = SvIV(val);
continue;
}
if (strEQ(key, "pic_height")) {
pic_height = SvIV(val);
continue;
}
if (strEQ(key, "pic_x")) {
pic_x = SvIV(val);
continue;
}
if (strEQ(key, "pic_y")) {
pic_y = SvIV(val);
continue;
}
if (strEQ(key, "colorspace")) {
colorspace = SvIV(val);