[Swfed-svn] swfed-svn [26] DefineSound タグの parse / build 処理を追加

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 8月 10日 (日) 01:36:44 JST


Revision: 26
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=swfed&view=rev&rev=26
Author:   yoya
Date:     2008-08-10 01:36:44 +0900 (Sun, 10 Aug 2008)

Log Message:
-----------
DefineSound タグの parse/build 処理を追加

Modified Paths:
--------------
    src/config.m4

Added Paths:
-----------
    src/swf_tag_sound.c
    src/swf_tag_sound.h


-------------- next part --------------
Modified: src/config.m4
===================================================================
--- src/config.m4	2008-08-08 11:08:17 UTC (rev 25)
+++ src/config.m4	2008-08-09 16:36:44 UTC (rev 26)
@@ -59,5 +59,5 @@
   dnl
   dnl PHP_SUBST(SWFED_SHARED_LIBADD)
 
-  PHP_NEW_EXTENSION(swfed, swfed.c swf_object.c swf_header.c swf_rect.c swf_tag.c swf_tag_jpeg.c swf_tag_edit.c swf_tag_action.c swf_tag_lossless.c swf_rgb.c swf_rgba.c swf_argb.c swf_xrgb.c swf_action.c swf_jpeg.c bitstream.c jpeg_segment.c swf_png.c swf_debug.c, $ext_shared)
+  PHP_NEW_EXTENSION(swfed, swfed.c swf_object.c swf_header.c swf_rect.c swf_tag.c swf_tag_jpeg.c swf_tag_edit.c swf_tag_action.c swf_tag_lossless.c swf_tag_sound.c swf_rgb.c swf_rgba.c swf_argb.c swf_xrgb.c swf_action.c swf_jpeg.c bitstream.c jpeg_segment.c swf_png.c swf_debug.c, $ext_shared)
 fi

Added: src/swf_tag_sound.c
===================================================================
--- src/swf_tag_sound.c	                        (rev 0)
+++ src/swf_tag_sound.c	2008-08-09 16:36:44 UTC (rev 26)
@@ -0,0 +1,145 @@
+/*
+  +----------------------------------------------------------------------+
+  | Author: yoya****@awm*****                                                  |
+  +----------------------------------------------------------------------+
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include "bitstream.h"
+#include "swf_tag_sound.h"
+#include "swf_object.h"
+
+swf_tag_detail_handler_t sound_detail_handler;
+
+swf_tag_detail_handler_t *
+swf_tag_sound_detail_handler(void) {
+    sound_detail_handler.create   = swf_tag_sound_create_detail;
+    sound_detail_handler.identity = swf_tag_sound_identity_detail;
+    sound_detail_handler.output   = swf_tag_sound_output_detail;
+    sound_detail_handler.print    = swf_tag_sound_print_detail;
+    sound_detail_handler.destroy  = swf_tag_sound_destroy_detail;
+    return &sound_detail_handler;
+}
+
+void *
+swf_tag_sound_create_detail(unsigned char *data, unsigned long length,
+                           swf_tag_t *tag,
+                           struct swf_object_ *swf) {
+    swf_tag_sound_detail_t *swf_tag_sound;
+    bitstream_t *bs;
+    unsigned long sound_data_len;
+    unsigned char *sound_data;
+    (void) tag;
+    swf_tag_sound = calloc(sizeof(*swf_tag_sound), 1);
+    if (swf_tag_sound == NULL) {
+        fprintf(stderr, "ERROR: swf_tag_sound_create_detail: can't calloc\n");
+        return NULL;
+    }
+    bs = bitstream_open();
+    bitstream_input(bs, data, length);
+    swf_tag_sound->sound_id = bitstream_getbytesLE(bs, 2);
+    swf_tag_sound->sound_format    = bitstream_getbits(bs, 4);
+    swf_tag_sound->sound_rate      = bitstream_getbits(bs, 2);
+    swf_tag_sound->sound_is_16bits = bitstream_getbit(bs);
+    swf_tag_sound->sound_is_stereo = bitstream_getbit(bs);
+    swf_tag_sound->sound_samples_count = bitstream_getbytesLE(bs, 4);
+    sound_data_len = bitstream_length(bs) - bitstream_getbytepos(bs);
+    swf_tag_sound->sound_data = malloc(sound_data_len);
+    if (swf_tag_sound->sound_data == NULL) {
+        fprintf(stderr, "swf_tag_sound_create_detail: swf_tag_sound->sound_data == NULL at line(%d): sound_data_len=%lu\n",
+                __LINE__, sound_data_len);
+        bitstream_close(bs);
+        return NULL;
+    }
+    sound_data = bitstream_buffer(bs, bitstream_getbytepos(bs));
+    memcpy(swf_tag_sound->sound_data, sound_data, sound_data_len);
+    swf_tag_sound->sound_data_len = sound_data_len;
+    bitstream_close(bs);
+    return (void *) swf_tag_sound;
+}
+
+int
+swf_tag_sound_identity_detail(unsigned char *data, int id, swf_tag_t *tag) {
+    int sound_id;
+    if (tag->detail) {
+        swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) tag->detail;        
+        if (swf_tag_sound->sound_id == id) {
+            return 0;
+        }        
+        return 1;
+    }
+    if (data == NULL) {
+        fprintf(stderr, "swf_tag_sound_identity_detail: data==NULL\n");
+        return 1;
+    }
+    sound_id = GetUShortLE(data);
+    if (id == sound_id) {
+        return 0;
+    }        
+    return 1;
+}
+
+unsigned char *
+swf_tag_sound_output_detail(void *detail, unsigned long *length,
+                           swf_tag_t *tag,
+                           struct swf_object_ *swf) {
+    swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) detail;
+    bitstream_t *bs;
+    unsigned char *data;
+    (void) tag;
+    *length = 0;
+    bs = bitstream_open();
+    bitstream_putbytesLE(bs, swf_tag_sound->sound_id, 2);
+    bitstream_putbits(bs, swf_tag_sound->sound_format, 4);
+    bitstream_putbits(bs, swf_tag_sound->sound_rate, 2);
+    bitstream_putbit(bs, swf_tag_sound->sound_is_16bits);
+    bitstream_putbit(bs, swf_tag_sound->sound_is_stereo);
+    bitstream_putbytesLE(bs, swf_tag_sound->sound_samples_count, 4);
+    bitstream_putstring(bs, swf_tag_sound->sound_data,
+                        swf_tag_sound->sound_data_len);
+    data = bitstream_steal(bs, length);
+    bitstream_close(bs);
+    return data;
+}
+
+void
+swf_tag_sound_print_detail(void *detail,
+                          swf_tag_t *tag,
+                          struct swf_object_ *swf) {
+    swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) detail;
+    (void) tag;
+    printf("\tsound_id=%d\n", swf_tag_sound->sound_id);
+    printf("\t");
+    printf("\tformat=%u rate=%u is_16bits=%u is_stereo=%u samples_count=%lu\n",
+           swf_tag_sound->sound_format,
+           swf_tag_sound->sound_rate,
+           swf_tag_sound->sound_is_16bits?1:0,
+           swf_tag_sound->sound_is_stereo?1:0,
+           swf_tag_sound->sound_samples_count);
+    printf("\tsound_data(length=%lu\n",
+           swf_tag_sound->sound_data_len);
+    return ;
+}
+
+void
+swf_tag_sound_destroy_detail(void *detail) {
+    swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) detail;
+    free(swf_tag_sound->sound_data);
+    free(swf_tag_sound);
+    return ;
+}
+
+
+char *
+swf_tag_sound_get_data(void *detail, int sound_id) {
+    // dummy
+    return NULL;
+}
+int
+swf_tag_sound_replace_data(void *detail, int sound_id,
+                                      unsigned char *data,
+                           unsigned long data_len) {
+        // dummy
+    return -1;
+}

Added: src/swf_tag_sound.h
===================================================================
--- src/swf_tag_sound.h	                        (rev 0)
+++ src/swf_tag_sound.h	2008-08-09 16:36:44 UTC (rev 26)
@@ -0,0 +1,45 @@
+/*
+  +----------------------------------------------------------------------+
+  | Author: yoya****@awm*****                                                  |
+  +----------------------------------------------------------------------+
+*/
+
+#ifndef __SWF_TAG_SOUND__H__
+#define __SWF_TAG_SOUND__H__
+
+#include "swf_tag.h"
+
+typedef struct swf_tag_sound_detail_ {
+    int sound_id;
+    int sound_format:4;
+    int sound_rate:2;
+    int sound_is_16bits:1;
+    int sound_is_stereo:1;
+    unsigned long sound_samples_count;
+    unsigned char *sound_data;
+    unsigned long sound_data_len;
+} swf_tag_sound_detail_t;
+
+extern swf_tag_detail_handler_t *swf_tag_sound_detail_handler(void);
+
+extern void *swf_tag_sound_create_detail(unsigned char *data,
+                                         unsigned long length,
+                                         swf_tag_t *tag,
+                                         struct swf_object_ *swf);
+extern int swf_tag_sound_identity_detail(unsigned char *data, int id,
+                                         swf_tag_t *tag);
+extern unsigned char *swf_tag_sound_output_detail(void *detail,
+                                                  unsigned long *length,
+                                                  swf_tag_t *tag,
+                                                  struct swf_object_ *swf);
+extern void swf_tag_sound_print_detail(void *detail,
+                                       swf_tag_t *tag,
+                                       struct swf_object_ *swf);
+extern void swf_tag_sound_destroy_detail(void *detail);
+
+extern char *swf_tag_sound_get_data(void *detail, int sound_id);
+extern int swf_tag_sound_replace_data(void *detail, int sound_id,
+                                      unsigned char *data,
+                                      unsigned long data_len);
+
+#endif /* __SWF_TAG_SOUND__H__ */


Swfed-svn メーリングリストの案内
Back to archive index