Ogg-Theora-LibTheora

 view release on metacpan or  search on metacpan

LibTheora.xs  view on Meta::CPAN

    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.xs  view on Meta::CPAN

    // 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;



( run in 0.329 second using v1.01-cache-2.11-cpan-5511b514fd6 )