OSDN Git Service

add bitmap_id parameter into apply factor method.
[swfed/swfed.git] / src / swf_tag_sound.c
index db2a58a..efd0917 100644 (file)
@@ -15,7 +15,9 @@ 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.input    = swf_tag_sound_input_detail;
+    sound_detail_handler.get_cid  = swf_tag_sound_get_cid_detail;
+    sound_detail_handler.replace_cid = swf_tag_sound_replace_cid_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;
@@ -23,20 +25,30 @@ swf_tag_sound_detail_handler(void) {
 }
 
 void *
-swf_tag_sound_create_detail(unsigned char *data, unsigned long length,
-                           swf_tag_t *tag,
-                           struct swf_object_ *swf) {
+swf_tag_sound_create_detail(void) {
     swf_tag_sound_detail_t *swf_tag_sound;
-    bitstream_t *bs;
-    unsigned long sound_data_len;
-    unsigned char *sound_data;
-    (void) tag;
-    (void) swf;
     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;
     }
+    return swf_tag_sound;
+}
+
+int
+swf_tag_sound_input_detail(swf_tag_t *tag,
+                            struct swf_object_ *swf) {
+    swf_tag_sound_detail_t *swf_tag_sound = tag->detail;
+    unsigned char *data  = tag->data;
+    unsigned long length = tag->length;
+    bitstream_t *bs;
+    unsigned long sound_data_len;
+    unsigned char *sound_data_ref;
+    (void) swf;
+    if (swf_tag_sound == NULL) {
+        fprintf(stderr, "ERROR: swf_tag_sound_input_detail: swf_tag_sound == NULL\n");
+        return 1;
+    }
     bs = bitstream_open();
     bitstream_input(bs, data, length);
     swf_tag_sound->sound_id = bitstream_getbytesLE(bs, 2);
@@ -51,41 +63,48 @@ swf_tag_sound_create_detail(unsigned char *data, unsigned long length,
         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;
+        return 1;
     }
-    sound_data = bitstream_buffer(bs, bitstream_getbytepos(bs));
-    memcpy(swf_tag_sound->sound_data, sound_data, sound_data_len);
+    sound_data_ref = bitstream_buffer(bs, bitstream_getbytepos(bs));
+    memcpy(swf_tag_sound->sound_data, sound_data_ref, sound_data_len);
     swf_tag_sound->sound_data_len = sound_data_len;
     bitstream_close(bs);
-    return (void *) swf_tag_sound;
+    return 0;
 }
 
 int
-swf_tag_sound_identity_detail(unsigned char *data, int id, swf_tag_t *tag) {
+swf_tag_sound_get_cid_detail(swf_tag_t *tag) {
     int sound_id;
+    unsigned char *data = tag->data;
     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;
+        swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) tag->detail;
+        return swf_tag_sound->sound_id;
     }
     if (data == NULL) {
-        fprintf(stderr, "swf_tag_sound_identity_detail: data==NULL\n");
-        return 1;
+        fprintf(stderr, "swf_tag_sound_get_cid_detail: data==NULL\n");
+        return -1;
     }
     sound_id = GetUShortLE(data);
-    if (id == sound_id) {
-        return 0;
+    return sound_id;
+}
+
+int
+swf_tag_sound_replace_cid_detail(swf_tag_t *tag, int id) {
+    unsigned char *data = tag->data;
+    if (tag->detail) {
+        swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) tag->detail;
+        swf_tag_sound->sound_id = id;
+    }
+    if (data == NULL) {
+        PutUShortLE(data, id);
     }        
-    return 1;
+    return 0; // always 0
 }
 
 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;
+swf_tag_sound_output_detail(swf_tag_t *tag, unsigned long *length,
+                            struct swf_object_ *swf) {
+    swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) tag->detail;
     bitstream_t *bs;
     unsigned char *data;
     (void) tag;
@@ -106,12 +125,10 @@ swf_tag_sound_output_detail(void *detail, unsigned long *length,
 }
 
 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;
+swf_tag_sound_print_detail(swf_tag_t *tag,
+                           struct swf_object_ *swf, int indent_depth) {
+    swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) tag->detail;
     char *format_name = "Unknown";
-    (void) tag;
     (void) swf;
     switch(swf_tag_sound->sound_format & 0x0f) {
     case 0:
@@ -131,26 +148,29 @@ swf_tag_sound_print_detail(void *detail,
         break;
         
     }
-    printf("\tsound_id=%d\n", swf_tag_sound->sound_id);
-    
-    printf("\tformat=%u(%s) rate=%u is_16bits=%u is_stereo=%u samples_count=%lu\n",
+    print_indent(indent_depth);
+    printf("sound_id=%d\n", swf_tag_sound->sound_id);
+    print_indent(indent_depth);    
+    printf("format=%u(%s) rate=%u is_16bits=%u is_stereo=%u samples_count=%lu\n",
            swf_tag_sound->sound_format & 0x0f, format_name,
            swf_tag_sound->sound_rate  & 0x03,
            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",
+    print_indent(indent_depth);    
+    printf("sound_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;
+swf_tag_sound_destroy_detail(swf_tag_t *tag) {
+    swf_tag_sound_detail_t *swf_tag_sound = (swf_tag_sound_detail_t *) tag->detail;
     if (swf_tag_sound) {
         free(swf_tag_sound->sound_data);
         swf_tag_sound->sound_data = NULL;
         free(swf_tag_sound);
+        tag->detail = NULL;
     }
     return ;
 }
@@ -195,9 +215,9 @@ swf_tag_sound_replace_melo_data(void *detail, int sound_id,
     (void) melo_data_len;
     swf_tag_sound->sound_id = sound_id;
     swf_tag_sound->sound_format = 15;
-    swf_tag_sound->sound_rate = 0;
-    swf_tag_sound->sound_is_16bits = 0;
-    swf_tag_sound->sound_is_stereo = 0;
+    swf_tag_sound->sound_rate          = 0;
+    swf_tag_sound->sound_is_16bits     = 0;
+    swf_tag_sound->sound_is_stereo     = 0;
     swf_tag_sound->sound_samples_count = 0;
     free(swf_tag_sound->sound_data);
     swf_tag_sound->sound_data = malloc(melo_data_len);
@@ -207,6 +227,5 @@ swf_tag_sound_replace_melo_data(void *detail, int sound_id,
     }
     memcpy(swf_tag_sound->sound_data, melo_data, melo_data_len);
     swf_tag_sound->sound_data_len = melo_data_len;
-        // dummy
     return 0;
 }