1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Miscellaneous helper API definitions
12 * Copyright (c) 2007 Michael Sevakis
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "mpegplayer.h"
28 /* Initializes the cursor */
29 void stream_scan_init(struct stream_scan
*sk
)
31 dbuf_l2_init(&sk
->l2
);
34 /* Ensures direction is -1 or 1 and margin is properly initialized */
35 void stream_scan_normalize(struct stream_scan
*sk
)
39 sk
->dir
= SSCAN_FORWARD
;
44 sk
->dir
= SSCAN_REVERSE
;
49 /* Moves a scan cursor. If amount is positive, the increment is in the scan
50 * direction, otherwise opposite the scan direction */
51 void stream_scan_offset(struct stream_scan
*sk
, off_t by
)
53 off_t bydir
= by
*sk
->dir
;
60 void ts_to_hms(uint32_t pts
, struct hms
*hms
)
62 hms
->frac
= pts
% TS_SECOND
;
63 hms
->sec
= pts
/ TS_SECOND
;
64 hms
->min
= hms
->sec
/ 60;
65 hms
->hrs
= hms
->min
/ 60;
70 void hms_format(char *buf
, size_t bufsize
, struct hms
*hms
)
72 /* Only display hours if nonzero */
75 rb
->snprintf(buf
, bufsize
, "%u:%02u:%02u",
76 hms
->hrs
, hms
->min
, hms
->sec
);
80 rb
->snprintf(buf
, bufsize
, "%u:%02u",
86 uint32_t muldiv_uint32(uint32_t multiplicand
,
92 uint64_t prod
= (uint64_t)multiplier
*multiplicand
+ divisor
/2;
94 if ((uint32_t)(prod
>> 32) < divisor
)
95 return (uint32_t)(prod
/ divisor
);
97 else if (multiplicand
== 0 || multiplier
== 0)
99 return 0; /* 0/0 = 0 : yaya */
101 /* else (> 0) / 0 = UINT32_MAX */
103 return UINT32_MAX
; /* Saturate */