File: mp3length.c

package info (click to toggle)
poc-streamer 0.4.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,000 kB
  • sloc: ansic: 8,782; makefile: 307; ruby: 152; perl: 135; yacc: 115; lex: 36; sh: 30
file content (58 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download | duplicates (5)
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
#include "conf.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "file.h"
#include "mp3.h"
#include "aq.h"
#include "misc.h"

static void usage(void) {
  fprintf(stderr, "Usage: mp3length mp3file\n");
}

int main(int argc, char *argv[]) {
  int retval = EXIT_SUCCESS;

  if (argc != 2) {
    usage();
    return EXIT_FAILURE;
  }

  file_t mp3file;
  if (!file_open_read(&mp3file, argv[1])) {
    fprintf(stderr, "Could not open mp3 file: %s\n", argv[1]);
    retval = EXIT_FAILURE;
    goto exit;
  }

  aq_t qin;
  aq_init(&qin);
  
  mp3_frame_t frame;
  int ret;
  unsigned long long time = 0;
  while ((ret = mp3_next_frame(&mp3file, &frame)) > 0) {
    if (aq_add_frame(&qin, &frame)) { 
      adu_t *adu = aq_get_adu(&qin);
      assert(adu != NULL);
      
      time += adu->usec;
      free(adu);
    }
  }
          
  file_close(&mp3file);
  aq_destroy(&qin);

  char buf[256];
  format_time(time / 1000, buf, sizeof(buf));
  printf("Length of %s: %s\n", argv[1], buf);

 exit:
  return retval;
}