~jcowgill/ubuntu/trusty/easytag/bug-1295882

« back to all changes in this revision

Viewing changes to src/libmpg123/mpg123.c

  • Committer: Package Import Robot
  • Author(s): James Cowgill, James Cowgill, Alessio Treglia
  • Date: 2014-02-28 15:50:09 UTC
  • mfrom: (8.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20140228155009-o7quqdw3qlldw98q
Tags: 2.1.10-1
* Team upload.

[ James Cowgill ]
* New upstream release (Closes: #560813, #500051, #518955, #727811).
* Add myself to the list of uploaders.
* Use debhelper v9.
* debian/control:
  - Build depend on desktop-file-utils and yelp-tools.
  - Recommend on gnome-icon-theme, gvfs and yelp (thanks David King)
  - Update homepage location.
  - Bump standards to 3.9.5 (no changes required).
* debian/copyright:
  - Rewritten to use DEP-5
* debian/rules:
  - Enable all hardening flags.
  - Remove unnecessary dh overrides.
* debian/patches:
  - Remove 1001-c90_style.patch, applied upstream.
  - Add patch to remove appdata from buildsystem.
    Can't use until appdata-tools is introduced into Debian.

[ Alessio Treglia ]
* Improve package description (Closes: #691687)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  XMMS - Cross-platform multimedia player
2
 
 *  Copyright (C) 1998-2000  Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies
3
 
 *  Copyright (C) 1999,2000  H�vard Kv�len
4
 
 *
5
 
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 
 */
19
 
 
20
 
/*
21
 
 * Note : removed code not used in EasyTAG
22
 
 */
23
 
 
24
 
#include "mpg123.h"
25
 
 
26
 
 
27
 
double mpg123_compute_tpf(struct frame *fr)
28
 
{
29
 
        const int bs[4] = {0, 384, 1152, 1152};
30
 
        double tpf;
31
 
 
32
 
        tpf = bs[fr->lay];
33
 
        tpf /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
34
 
        return tpf;
35
 
}
36
 
 
37
 
 
38
 
static guint32 convert_to_header(guint8 * buf)
39
 
{
40
 
 
41
 
        return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
42
 
}
43
 
 
44
 
 
45
 
#define DET_BUF_SIZE 1024
46
 
 
47
 
#if 0 /* Not used at the present time */
48
 
static gboolean mpg123_detect_by_content(gchar *filename)
49
 
{
50
 
        FILE *file;
51
 
        guchar tmp[4];
52
 
        guint32 head;
53
 
        struct frame fr;
54
 
        guchar buf[DET_BUF_SIZE];
55
 
        gint in_buf, i;
56
 
 
57
 
        if((file = fopen(filename, "rb")) == NULL)
58
 
                return FALSE;
59
 
        if (fread(tmp, 1, 4, file) != 4)
60
 
                goto done;
61
 
        head = convert_to_header(tmp);
62
 
        while(!mpg123_head_check(head))
63
 
        {
64
 
                /*
65
 
                 * The mpeg-stream can start anywhere in the file,
66
 
                 * so we check the entire file
67
 
                 */
68
 
                /* Optimize this */
69
 
                in_buf = fread(buf, 1, DET_BUF_SIZE, file);
70
 
                if(in_buf == 0)
71
 
                        goto done;
72
 
 
73
 
                for (i = 0; i < in_buf; i++)
74
 
                {
75
 
                        head <<= 8;
76
 
                        head |= buf[i];
77
 
                        if(mpg123_head_check(head))
78
 
                        {
79
 
                                fseek(file, i+1-in_buf, SEEK_CUR);
80
 
                                break;
81
 
                        }
82
 
                }
83
 
        }
84
 
        if (mpg123_decode_header(&fr, head))
85
 
        {
86
 
                /*
87
 
                 * We found something which looks like a MPEG-header.
88
 
                 * We check the next frame too, to be sure
89
 
                 */
90
 
                
91
 
                if (fseek(file, fr.framesize, SEEK_CUR) != 0)
92
 
                        goto done;
93
 
                if (fread(tmp, 1, 4, file) != 4)
94
 
                        goto done;
95
 
                head = convert_to_header(tmp);
96
 
                if (mpg123_head_check(head) && mpg123_decode_header(&fr, head))
97
 
                {
98
 
                        fclose(file);
99
 
                        return TRUE;
100
 
                }
101
 
        }
102
 
 
103
 
 done:
104
 
        fclose(file);
105
 
        return FALSE;
106
 
}
107
 
#endif
108
 
 
109
 
//static guint get_song_time(FILE * file)
110
 
guint mpg123_get_song_time(FILE * file)
111
 
{
112
 
        guint32 head;
113
 
        guchar tmp[4], *buf;
114
 
        struct frame frm;
115
 
        XHEADDATA xing_header;
116
 
        double tpf, bpf;
117
 
        guint32 len;
118
 
        long id3v2size = 0;                     
119
 
 
120
 
        if (!file)
121
 
                return -1;
122
 
 
123
 
        fseek(file, 0, SEEK_SET);
124
 
        if (fread(tmp, 1, 4, file) != 4)
125
 
                return 0;
126
 
 
127
 
    // Skip data of the ID3v2.x tag (patch from Artur Polaczynski)
128
 
        if (tmp[0] == 'I' && tmp[1] == 'D' && tmp[2] == '3' && tmp[3] < 0xFF)
129
 
        {
130
 
                // id3v2 tag skipeer $49 44 33 yy yy xx zz zz zz zz [zz size]
131
 
                fseek(file, 2, SEEK_CUR); // Size is 6-9 position
132
 
                if (fread(tmp, 1, 4, file) != 4)
133
 
                        return 0;
134
 
                id3v2size = 10 + ( (long)(tmp[3]) | ((long)(tmp[2]) << 7) | ((long)(tmp[1]) << 14) | ((long)(tmp[0]) << 21) );
135
 
                fseek(file, id3v2size, SEEK_SET);
136
 
                if (fread(tmp, 1, 4, file) != 4) // Read mpeg header
137
 
                        return 0;
138
 
        }
139
 
 
140
 
        head = convert_to_header(tmp);
141
 
        while (!mpg123_head_check(head))
142
 
        {
143
 
                head <<= 8;
144
 
                if (fread(tmp, 1, 1, file) != 1)
145
 
                        return 0;
146
 
                head |= tmp[0];
147
 
        }
148
 
        if (mpg123_decode_header(&frm, head))
149
 
        {
150
 
                buf = g_malloc(frm.framesize + 4);
151
 
                fseek(file, -4, SEEK_CUR);
152
 
                fread(buf, 1, frm.framesize + 4, file);
153
 
                xing_header.toc = NULL;
154
 
                tpf = mpg123_compute_tpf(&frm);
155
 
                if (mpg123_get_xing_header(&xing_header, buf))
156
 
                {
157
 
                        g_free(buf);
158
 
                        return ((guint) (tpf * xing_header.frames * 1000));
159
 
                }
160
 
                g_free(buf);
161
 
                bpf = mpg123_compute_bpf(&frm);
162
 
                fseek(file, 0, SEEK_END);
163
 
                len = ftell(file) - id3v2size;
164
 
                fseek(file, -128, SEEK_END);
165
 
                fread(tmp, 1, 3, file);
166
 
                if (!strncmp((gchar *)tmp, "TAG", 3))
167
 
                        len -= 128;
168
 
                return ((guint) ((guint)(len / bpf) * tpf * 1000));
169
 
        }
170
 
        return 0;
171
 
}
172