summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/mpeg_misc.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-12-29 19:46:35 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-12-29 19:46:35 +0000
commita222f27c4a17ed8f9809cda7861fe5f23d4cc0c1 (patch)
treed393a23d83549f99772bb156e59ffb88725148b6 /apps/plugins/mpegplayer/mpeg_misc.c
parent1d0f6b90ff43776e55b4b9f062c9bea3f99aa768 (diff)
downloadrockbox-a222f27c4a17ed8f9809cda7861fe5f23d4cc0c1.tar.gz
rockbox-a222f27c4a17ed8f9809cda7861fe5f23d4cc0c1.zip
mpegplayer: Make playback engine fully seekable and frame-accurate and split into logical parts. Be sure to have all current features work. Actual UI for seeking will be added soon. Recommended GOP size is about 15-30 frames depending on target or seeking can be slow with really long GOPs (nature of MPEG video). More refined encoding recommendations for a particular player should be posted soon.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15977 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/mpegplayer/mpeg_misc.c')
-rw-r--r--apps/plugins/mpegplayer/mpeg_misc.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/apps/plugins/mpegplayer/mpeg_misc.c b/apps/plugins/mpegplayer/mpeg_misc.c
new file mode 100644
index 0000000000..f5ecb6d6c8
--- /dev/null
+++ b/apps/plugins/mpegplayer/mpeg_misc.c
@@ -0,0 +1,96 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Miscellaneous helper API definitions
11 *
12 * Copyright (c) 2007 Michael Sevakis
13 *
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "plugin.h"
22#include "mpegplayer.h"
23
24/** Streams **/
25
26/* Ensures direction is -1 or 1 and margin is properly initialized */
27void stream_scan_normalize(struct stream_scan *sk)
28{
29 if (sk->dir >= 0)
30 {
31 sk->dir = SSCAN_FORWARD;
32 sk->margin = sk->len;
33 }
34 else if (sk->dir < 0)
35 {
36 sk->dir = SSCAN_REVERSE;
37 sk->margin = 0;
38 }
39}
40
41/* Moves a scan cursor. If amount is positive, the increment is in the scan
42 * direction, otherwise opposite the scan direction */
43void stream_scan_offset(struct stream_scan *sk, off_t by)
44{
45 off_t bydir = by*sk->dir;
46 sk->pos += bydir;
47 sk->margin -= bydir;
48 sk->len -= by;
49}
50
51/** Time helpers **/
52void ts_to_hms(uint32_t pts, struct hms *hms)
53{
54 hms->frac = pts % TS_SECOND;
55 hms->sec = pts / TS_SECOND;
56 hms->min = hms->sec / 60;
57 hms->hrs = hms->min / 60;
58 hms->sec %= 60;
59 hms->min %= 60;
60}
61
62void hms_format(char *buf, size_t bufsize, struct hms *hms)
63{
64 /* Only display hours if nonzero */
65 if (hms->hrs != 0)
66 {
67 rb->snprintf(buf, bufsize, "%u:%02u:%02u",
68 hms->hrs, hms->min, hms->sec);
69 }
70 else
71 {
72 rb->snprintf(buf, bufsize, "%u:%02u",
73 hms->min, hms->sec);
74 }
75}
76
77/** Maths **/
78uint32_t muldiv_uint32(uint32_t multiplicand,
79 uint32_t multiplier,
80 uint32_t divisor)
81{
82 if (divisor != 0)
83 {
84 uint64_t prod = (uint64_t)multiplier*multiplicand + divisor/2;
85
86 if ((uint32_t)(prod >> 32) < divisor)
87 return (uint32_t)(prod / divisor);
88 }
89 else if (multiplicand == 0 || multiplier == 0)
90 {
91 return 0; /* 0/0 = 0 : yaya */
92 }
93 /* else (> 0) / 0 = UINT32_MAX */
94
95 return UINT32_MAX; /* Saturate */
96}