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 /* Ensures direction is -1 or 1 and margin is properly initialized */
29 void stream_scan_normalize(struct stream_scan
*sk
)
33 sk
->dir
= SSCAN_FORWARD
;
38 sk
->dir
= SSCAN_REVERSE
;
43 /* Moves a scan cursor. If amount is positive, the increment is in the scan
44 * direction, otherwise opposite the scan direction */
45 void stream_scan_offset(struct stream_scan
*sk
, off_t by
)
47 off_t bydir
= by
*sk
->dir
;
54 void ts_to_hms(uint32_t pts
, struct hms
*hms
)
56 hms
->frac
= pts
% TS_SECOND
;
57 hms
->sec
= pts
/ TS_SECOND
;
58 hms
->min
= hms
->sec
/ 60;
59 hms
->hrs
= hms
->min
/ 60;
64 void hms_format(char *buf
, size_t bufsize
, struct hms
*hms
)
66 /* Only display hours if nonzero */
69 rb
->snprintf(buf
, bufsize
, "%u:%02u:%02u",
70 hms
->hrs
, hms
->min
, hms
->sec
);
74 rb
->snprintf(buf
, bufsize
, "%u:%02u",
80 uint32_t muldiv_uint32(uint32_t multiplicand
,
86 uint64_t prod
= (uint64_t)multiplier
*multiplicand
+ divisor
/2;
88 if ((uint32_t)(prod
>> 32) < divisor
)
89 return (uint32_t)(prod
/ divisor
);
91 else if (multiplicand
== 0 || multiplier
== 0)
93 return 0; /* 0/0 = 0 : yaya */
95 /* else (> 0) / 0 = UINT32_MAX */
97 return UINT32_MAX
; /* Saturate */