~ubuntu-branches/ubuntu/natty/libextractor/natty

« back to all changes in this revision

Viewing changes to src/plugins/flvextractor.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-11-17 20:27:32 UTC
  • mfrom: (1.10.4 upstream) (5.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091117202732-ipm2h3gks5bdw2vx
Tags: 0.5.23+dfsg-3
* Building against libltdl7.
* Updating to standards version 3.8.3.
* Adding maintainer homepage field to control.
* Marking maintainer homepage field to be also included in binary
  packages and changelog.
* Adding README.source.
* Simplifying autotools handling in rules.
* Updating README.source.
* Moving maintainer homepage field from control to copyright.
* Dropping la files.
* Simplyfing debhelper install files.
* Bumping versioned build-depends on debhelper.
* Adding depends to dpkg install info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
  const unsigned char *ptr = *data;
118
118
  double val;
119
119
 
120
 
  floatformat_to_double(&floatformat_ieee_double_big, 
121
 
                        (const void *)ptr, 
 
120
  EXTRACTOR_common_floatformat_to_double(&EXTRACTOR_floatformat_ieee_double_big,
 
121
                        (const void *)ptr,
122
122
                        &val);
123
123
  ptr += 8;
124
124
  *data = ptr;
152
152
{
153
153
  const unsigned char *ptr = *data;
154
154
  int val;
155
 
  
 
155
 
156
156
  if (*len < 1)
157
157
    return -1;
158
158
 
192
192
  const unsigned char *ptr = *data;
193
193
  char *ret;
194
194
  int slen;
195
 
 
 
195
 
196
196
  if (*len < 2)
197
197
    return -1;
198
198
 
214
214
  return 0;
215
215
}
216
216
 
217
 
static int parse_amf(const unsigned char **data, 
 
217
static int parse_amf(const unsigned char **data,
218
218
              size_t *len,
219
 
              AMFParserHandler *handler) 
 
219
              AMFParserHandler *handler)
220
220
{
221
221
  const unsigned char *ptr = *data;
222
222
  unsigned char astype;
231
231
      double val;
232
232
      ret = readASNumber(&ptr, len, &val);
233
233
      if (ret == 0)
234
 
        (*(handler->as_end_callback))(astype, 
235
 
                                      &val, 
 
234
        (*(handler->as_end_callback))(astype,
 
235
                                      &val,
236
236
                                      handler->userdata);
237
237
      break;
238
238
    }
241
241
      int val;
242
242
      ret = readASBoolean(&ptr, len, &val);
243
243
      if (ret == 0)
244
 
        (*(handler->as_end_callback))(astype, 
245
 
                                      &val, 
 
244
        (*(handler->as_end_callback))(astype,
 
245
                                      &val,
246
246
                                      handler->userdata);
247
247
      break;
248
248
    }
251
251
      char *val;
252
252
      ret = readASString(&ptr, len, &val);
253
253
      if (ret == 0) {
254
 
        (*(handler->as_end_callback))(astype, 
255
 
                                      val, 
 
254
        (*(handler->as_end_callback))(astype,
 
255
                                      val,
256
256
                                      handler->userdata);
257
257
        free(val);
258
258
      }
267
267
      tmp[0] = &millis;
268
268
      tmp[1] = &tz;
269
269
      if (ret == 0)
270
 
        (*(handler->as_end_callback))(astype, 
271
 
                                      &tmp, 
 
270
        (*(handler->as_end_callback))(astype,
 
271
                                      &tmp,
272
272
                                      handler->userdata);
273
273
      break;
274
274
    }
293
293
        if (ret == -1)
294
294
          break;
295
295
      }
296
 
      (*(handler->as_end_callback))(ASTYPE_ARRAY, 
297
 
                                    NULL, 
 
296
      (*(handler->as_end_callback))(ASTYPE_ARRAY,
 
297
                                    NULL,
298
298
                                    handler->userdata);
299
299
      break;
300
 
    }  
 
300
    }
301
301
    case ASTYPE_OBJECT:
302
302
    {
303
303
      char *key;
306
306
      ret = readASString(&ptr, len, &key);
307
307
      if (ret == -1)
308
308
        break;
309
 
      (*(handler->as_key_callback))(key, 
 
309
      (*(handler->as_key_callback))(key,
310
310
                                    handler->userdata);
311
311
      free(key);
312
312
      type = *ptr;
317
317
        ret = readASString(&ptr, len, &key);
318
318
        if (ret == -1)
319
319
          break;
320
 
        (*(handler->as_key_callback))(key, 
 
320
        (*(handler->as_key_callback))(key,
321
321
                                      handler->userdata);
322
322
        free(key);
323
 
        type = *ptr;      
 
323
        type = *ptr;
324
324
      }
325
325
      if (ret == 0)
326
 
        (*(handler->as_end_callback))(ASTYPE_OBJECT, 
327
 
                                      NULL, 
 
326
        (*(handler->as_end_callback))(ASTYPE_OBJECT,
 
327
                                      NULL,
328
328
                                      handler->userdata);
329
329
      break;
330
 
    }  
 
330
    }
331
331
    case ASTYPE_MIXEDARRAY:
332
332
    {
333
333
      char *key;
343
343
      ret = readASString(&ptr, len, &key);
344
344
      if (ret == -1)
345
345
        break;
346
 
      (*(handler->as_key_callback))(key, 
 
346
      (*(handler->as_key_callback))(key,
347
347
                                    handler->userdata);
348
348
      free(key);
349
349
      type = *ptr;
354
354
        ret = readASString(&ptr, len, &key);
355
355
        if (ret == -1)
356
356
          break;
357
 
        (*(handler->as_key_callback))(key, 
 
357
        (*(handler->as_key_callback))(key,
358
358
                                      handler->userdata);
359
359
        free(key);
360
 
        type = *ptr;      
 
360
        type = *ptr;
361
361
      }
362
362
      if (ret == 0)
363
 
        (*(handler->as_end_callback))(astype, 
364
 
                                      NULL, 
 
363
        (*(handler->as_end_callback))(astype,
 
364
                                      NULL,
365
365
                                      handler->userdata);
366
366
      break;
367
 
    }  
 
367
    }
368
368
    default:
369
369
      ret = -1;
370
 
      (*(handler->as_end_callback))(astype, 
371
 
                                    NULL, 
 
370
      (*(handler->as_end_callback))(astype,
 
371
                                    NULL,
372
372
                                    handler->userdata);
373
373
#if DEBUG
374
374
      printf("parse_amf: Unknown type %02x", astype);
521
521
#define FLV_TAG_HEADER_SIZE 11
522
522
 
523
523
static int readFLVHeader(const unsigned char **data,
524
 
                          const unsigned char *end,
525
 
                          FLVHeader *hdr)
 
524
                         const unsigned char *end,
 
525
                         FLVHeader *hdr)
526
526
{
527
527
  const unsigned char *ptr = *data;
528
528
 
647
647
{
648
648
  FLVMetaParserState *state = (FLVMetaParserState *)userdata;
649
649
 
650
 
  if (state->onMetaData && state->parsingDepth == 0 && 
 
650
  if (state->onMetaData && state->parsingDepth == 0 &&
651
651
      type != ASTYPE_MIXEDARRAY)
652
652
    state->onMetaData = 0;
653
653
 
654
 
  if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || 
 
654
  if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY ||
655
655
      type == ASTYPE_OBJECT)
656
656
    state->parsingDepth++;
657
657
}
665
665
    return;
666
666
 
667
667
  i = 0;
668
 
  while ((key_to_extractor_map[i].key != NULL) && 
 
668
  while ((key_to_extractor_map[i].key != NULL) &&
669
669
         (strcasecmp(key, key_to_extractor_map[i].key) != 0))
670
670
    i++;
671
671
  state->currentKeyType = key_to_extractor_map[i].type;
672
672
 
673
673
  i = 0;
674
 
  while ((key_to_attribute_map[i].key != NULL) && 
 
674
  while ((key_to_attribute_map[i].key != NULL) &&
675
675
         (strcasecmp(key, key_to_attribute_map[i].key) != 0))
676
676
    i++;
677
677
  state->currentAttribute = key_to_attribute_map[i].attribute;
681
681
{
682
682
  FLVMetaParserState *state = (FLVMetaParserState *)userdata;
683
683
  char *s;
684
 
  
 
684
 
685
685
  if ((state->parsingDepth == 0) && (type == ASTYPE_STRING)) {
686
686
    s = (char *)value;
687
687
    if (!strcmp(s, "onMetaData"))
692
692
   * right after a "onMetaData" STRING */
693
693
 
694
694
  /* stream info related metadata */
695
 
  if (state->onMetaData && (state->parsingDepth == 1) && 
696
 
      (state->currentAttribute != FLV_NONE) && 
 
695
  if (state->onMetaData && (state->parsingDepth == 1) &&
 
696
      (state->currentAttribute != FLV_NONE) &&
697
697
      (type == ASTYPE_NUMBER))
698
698
  {
699
699
    double n = *((double *)value);
711
711
        break;
712
712
      case FLV_FRAMERATE:
713
713
        state->streamInfo->videoFrameRate = n;
714
 
        break; 
 
714
        break;
715
715
      case FLV_VDATARATE:
716
716
        state->streamInfo->videoDataRate = n;
717
 
        break; 
 
717
        break;
718
718
      case FLV_ADATARATE:
719
719
        state->streamInfo->audioDataRate = n;
720
720
        break;
729
729
    }
730
730
  }
731
731
 
732
 
  if (state->onMetaData && (state->parsingDepth == 1) && 
733
 
      (state->currentAttribute == FLV_STEREO) && 
 
732
  if (state->onMetaData && (state->parsingDepth == 1) &&
 
733
      (state->currentAttribute == FLV_STEREO) &&
734
734
      (type == ASTYPE_BOOLEAN))
735
735
  {
736
736
    int n = *((int *)value);
739
739
  }
740
740
 
741
741
  /* metadata that maps straight to extractor keys */
742
 
  if (state->onMetaData && (state->parsingDepth == 1) && 
 
742
  if (state->onMetaData && (state->parsingDepth == 1) &&
743
743
      (state->currentKeyType != EXTRACTOR_UNKNOWN))
744
744
  {
745
745
    s = NULL;
779
779
    }
780
780
 
781
781
    if (s != NULL)
782
 
      state->keywords = addKeyword (state->currentKeyType, 
 
782
      state->keywords = addKeyword (state->currentKeyType,
783
783
                                    s,
784
784
                                    state->keywords);
785
785
  }
786
786
  state->currentKeyType = EXTRACTOR_UNKNOWN;
787
787
  state->currentAttribute = FLV_NONE;
788
788
 
789
 
  if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY || 
 
789
  if (type == ASTYPE_ARRAY || type == ASTYPE_MIXEDARRAY ||
790
790
      type == ASTYPE_OBJECT)
791
791
    state->parsingDepth--;
792
792
}
793
793
 
794
794
static struct EXTRACTOR_Keywords *
795
 
handleMetaBody(const unsigned char *data, size_t len, 
 
795
handleMetaBody(const unsigned char *data, size_t len,
796
796
                FLVStreamInfo *stinfo,
797
 
                struct EXTRACTOR_Keywords *prev) 
 
797
                struct EXTRACTOR_Keywords *prev)
798
798
{
799
799
  AMFParserHandler handler;
800
800
  FLVMetaParserState pstate;
843
843
};
844
844
 
845
845
static struct EXTRACTOR_Keywords *
846
 
handleAudioBody(const unsigned char *data, size_t len, 
 
846
handleAudioBody(const unsigned char *data, size_t len,
847
847
                FLVStreamInfo *stinfo,
848
 
                struct EXTRACTOR_Keywords *prev) 
 
848
                struct EXTRACTOR_Keywords *prev)
849
849
{
850
850
  stinfo->audioChannels = *data & 0x01;
851
851
  stinfo->audioSampleBits = (*data & 0x02) >> 1;
878
878
};
879
879
 
880
880
static struct EXTRACTOR_Keywords *
881
 
handleVideoBody(const unsigned char *data, size_t len, 
 
881
handleVideoBody(const unsigned char *data, size_t len,
882
882
                FLVStreamInfo *stinfo,
883
 
                struct EXTRACTOR_Keywords *prev) 
 
883
                struct EXTRACTOR_Keywords *prev)
884
884
{
885
885
  int codecId, frameType;
886
886
 
938
938
        if (separated_coeff || !filter_header) {
939
939
          data += 2;
940
940
        }
941
 
        /* XXX encoded/displayed dimensions might vary, but which are the 
 
941
        /* XXX encoded/displayed dimensions might vary, but which are the
942
942
         * right ones? */
943
943
        stinfo->videoWidth = (data[3]*16) - (dim_adj>>4);
944
944
        stinfo->videoHeight = (data[2]*16) - (dim_adj&0x0F);
968
968
  if ((ptr + header.bodyLength) > end)
969
969
    return -1;
970
970
 
971
 
  switch (header.type) 
 
971
  switch (header.type)
972
972
  {
973
973
    case FLV_TAG_TYPE_AUDIO:
974
974
      head = handleAudioBody(ptr, header.bodyLength, stinfo, head);
984
984
  }
985
985
 
986
986
  ptr += header.bodyLength;
987
 
  
 
987
 
988
988
  *list = head;
989
989
  *data = ptr;
990
990
  return 0;
1038
1038
      n += snprintf(s+n, len-n, "%.4f kbps", stinfo->videoDataRate);
1039
1039
  }
1040
1040
 
1041
 
  if (n == 0) 
 
1041
  if (n == 0)
1042
1042
    return NULL;
1043
1043
  return strdup(s);
1044
1044
}
1058
1058
    if (n > 0)
1059
1059
      n += snprintf(s+n, len-n, ", ");
1060
1060
    if (n < len)
1061
 
      n += snprintf(s+n, len-n, "%s", 
 
1061
      n += snprintf(s+n, len-n, "%s",
1062
1062
                    FLVAudioSampleSizes[stinfo->audioSampleBits]);
1063
1063
  }
1064
1064
 
1066
1066
    if (n > 0)
1067
1067
      n += snprintf(s+n, len-n, ", ");
1068
1068
    if (n < len)
1069
 
      n += snprintf(s+n, len-n, "%s", 
 
1069
      n += snprintf(s+n, len-n, "%s",
1070
1070
                    FLVAudioChannels[stinfo->audioChannels]);
1071
1071
  }
1072
1072
 
1085
1085
      n += snprintf(s+n, len-n, "%.4f kbps", stinfo->audioDataRate);
1086
1086
  }
1087
1087
 
1088
 
  if (n == 0) 
 
1088
  if (n == 0)
1089
1089
    return NULL;
1090
1090
  return strdup(s);
1091
1091
}