source: svn/newcon3bcm2_21bu/nexus/modules/file/src/nexus_file.c @ 47

Last change on this file since 47 was 47, checked in by megakiss, 11 years ago

459Mhz로 OTC 주파수 변경

  • Property svn:executable set to *
File size: 10.6 KB
Line 
1/***************************************************************************
2 *     (c)2010-2011 Broadcom Corporation
3 *
4 *  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5 *  and may only be used, duplicated, modified or distributed pursuant to the terms and
6 *  conditions of a separate, written license agreement executed between you and Broadcom
7 *  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8 *  no license (express or implied), right to use, or waiver of any kind with respect to the
9 *  Software, and Broadcom expressly reserves all rights in and to the Software and all
10 *  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11 *  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12 *  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13 *
14 *  Except as expressly set forth in the Authorized License,
15 *
16 *  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17 *  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18 *  and to use this information only in connection with your use of Broadcom integrated circuit products.
19 *
20 *  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21 *  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22 *  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23 *  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24 *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25 *  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26 *  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27 *  USE OR PERFORMANCE OF THE SOFTWARE.
28 *
29 *  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30 *  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31 *  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32 *  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33 *  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34 *  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35 *  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36 *  ANY LIMITED REMEDY.
37 *
38 * $brcm_Workfile: nexus_file.c $
39 * $brcm_Revision: 6 $
40 * $brcm_Date: 4/7/11 6:13p $
41 *
42 * Module Description:
43 *
44 * Revision History:
45 *
46 * $brcm_Log: /nexus/modules/file/src/nexus_file.c $
47 *
48 * 6   4/7/11 6:13p vsilyaev
49 * SW7425-232: Updated file mux module
50 *
51 * 5   4/6/11 6:53p vsilyaev
52 * SW7425-232: Removed MuxFileIo API to avoid naming clashes
53 *
54 * 4   4/6/11 4:45p vsilyaev
55 * SW7425-232: Added MuxFile interface
56 *
57 * 3   2/25/11 12:47p erickson
58 * SW7125-818: use BNAV_GetEntrySize
59 *
60 * 2   11/11/10 5:17p vsilyaev
61 * SW7405-4995: Use BKNI_Memcmp to preinitialize structure used in
62 *  GetDefaultSettings
63 *
64 * 1   9/22/10 6:57p vsilyaev
65 * SW7405-4419: Added functions for file editing
66 *
67 *
68 **************************************************************************/
69#include "nexus_file_module.h"
70#include "bcmplayer.h"
71#include "bfile_util.h"
72#include "nexus_file_muxio.h"
73#include "nexus_file_posix.h"
74
75BDBG_MODULE("nexus_file");
76
77typedef struct b_file_bp_info {
78    unsigned index_entrysize;
79    NEXUS_FilePlayHandle play_file;
80} b_file_bp_info;
81
82static long
83bp_read(void *buffer, long size, long count, void *fp )
84{
85    bfile_io_read_t f = ((b_file_bp_info *)fp)->play_file->file.index;
86
87    return (long)f->read(f, buffer, (size_t)(count*size));
88}
89
90static long
91bp_tell( void *fp )
92{
93    bfile_io_read_t f = ((b_file_bp_info *)fp)->play_file->file.index;
94    return (long)f->seek(f, 0, SEEK_CUR);
95}
96
97static int
98bp_seek( void *fp, long offset, int origin )
99{
100    bfile_io_read_t f = ((b_file_bp_info *)fp)->play_file->file.index;
101    off_t rc;
102    rc = f->seek(f, (off_t)offset, origin);
103    if ( rc == (off_t)-1) {
104        return -1;
105    }
106    return 0;
107}
108
109static int
110bp_bounds(BNAV_Player_Handle handle, void *fp, long *firstIndex, long *lastIndex)
111{
112    bfile_io_read_t f = ((b_file_bp_info *)fp)->play_file->file.index;
113    off_t first, last;
114    unsigned index_entrysize =((b_file_bp_info *)fp)->index_entrysize;
115
116    f->bounds(f, &first, &last);
117
118    BSTD_UNUSED(handle);
119    *firstIndex = first/index_entrysize;
120    *lastIndex = (last-1)/index_entrysize;
121
122    return 0;
123}
124
125void
126NEXUS_P_FilePlay_ConvertPosition(unsigned index_entrysize, const BNAV_Player_Position *nav_position, NEXUS_FilePosition *position)
127{
128   position->indexOffset = nav_position->index * index_entrysize;
129   position->timestamp = nav_position->timestamp;
130   position->mpegFileOffset = ((nav_position)->offsetLo|(((uint64_t)(nav_position)->offsetHi)<<32));
131   return;
132}
133
134NEXUS_Error
135NEXUS_P_FilePlay_OpenBcmPlayer(BNAV_Player_Handle *bcm_player, b_file_bp_info *bp_info, NEXUS_FilePlayHandle file)
136{
137    NEXUS_Error rc;
138    BNAV_Player_Settings cfg;
139    static const BNAV_DecoderFeatures features = {1,1,1,1};
140
141    if(file->file.index==NULL) { rc = BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_args; }
142
143    BNAV_Player_GetDefaultSettings(&cfg);
144    bp_info->index_entrysize = BNAV_GetEntrySize(BNAV_VersionOriginal); /* default */
145    bp_info->play_file = file;
146    cfg.videoPid = 0x1FFF; /* since BNAV_Player doesn't like 0 */
147    cfg.filePointer = bp_info;
148    cfg.decoderFeatures = features;
149    cfg.readCb = bp_read;
150    cfg.tellCb = bp_tell;
151    cfg.seekCb   = bp_seek;
152    cfg.boundsCb = bp_bounds;
153    cfg.transportTimestampEnabled = false;
154
155    if (BNAV_Player_Open(bcm_player, &cfg)!=0) { rc=BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_player; }
156
157    BNAV_Player_GetSettings(*bcm_player, &cfg);
158    bp_info->index_entrysize = BNAV_GetEntrySize(cfg.navVersion);
159    return NEXUS_SUCCESS;
160
161err_player:
162    BNAV_Player_Close(*bcm_player);
163err_args:
164    return rc;
165}
166
167
168NEXUS_Error
169NEXUS_FilePlay_GetBounds(NEXUS_FilePlayHandle file, NEXUS_FilePosition *pFirst,  NEXUS_FilePosition *pLast)
170{
171    b_file_bp_info bp_info;
172    int i_rc;
173    NEXUS_Error rc;
174    BNAV_Player_Handle bcm_player;
175    long firstIndex, lastIndex;
176    BNAV_Player_Position first, last;
177
178    BDBG_ASSERT(file);
179    BDBG_ASSERT(pFirst);
180    BDBG_ASSERT(pLast);
181
182    rc = NEXUS_P_FilePlay_OpenBcmPlayer(&bcm_player, &bp_info, file);
183    if(rc!=NEXUS_SUCCESS) {goto err_player;}
184
185    i_rc = bp_bounds(bcm_player, &bp_info, &firstIndex, &lastIndex);
186    if(i_rc!=0) { rc=BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_bounds;}
187    i_rc = BNAV_Player_GetPositionInformation(bcm_player, firstIndex, &first);
188    if(i_rc!=0) { rc=BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_first;}
189    i_rc = BNAV_Player_GetPositionInformation(bcm_player, lastIndex, &last);
190    if(i_rc!=0) { rc=BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_last;}
191    NEXUS_P_FilePlay_ConvertPosition(bp_info.index_entrysize, &first, pFirst);
192    NEXUS_P_FilePlay_ConvertPosition(bp_info.index_entrysize, &last, pLast);
193    BNAV_Player_Close(bcm_player);
194    return NEXUS_SUCCESS;
195
196err_last:
197err_first:
198err_bounds:
199    BNAV_Player_Close(bcm_player);
200err_player:
201    return rc;
202}
203
204NEXUS_Error
205NEXUS_FilePlay_GetLocation( NEXUS_FilePlayHandle file, unsigned long timestamp, NEXUS_FilePosition *pPosition )
206{
207    b_file_bp_info bp_info;
208    int i_rc;
209    NEXUS_Error rc;
210    BNAV_Player_Handle bcm_player;
211    long i_frame_index;
212    BNAV_Player_Position i_frame_position;
213    long index;
214
215    rc = NEXUS_P_FilePlay_OpenBcmPlayer(&bcm_player, &bp_info, file);
216    if(rc!=NEXUS_SUCCESS) {goto err_player;}
217
218    index = BNAV_Player_FindIndexFromTimestamp(bcm_player, timestamp);
219    if(index==-1)  {rc=BERR_TRACE(NEXUS_NOT_SUPPORTED);goto err_find_index;}
220
221    i_frame_index = BNAV_Player_FindIFrameFromIndex(bcm_player, index, eBpForward);
222    if (i_frame_index == -1) { rc=BERR_TRACE(NEXUS_NOT_SUPPORTED);goto err_find_iframe;}
223
224    i_rc = BNAV_Player_GetPositionInformation(bcm_player, i_frame_index, &i_frame_position);
225    if(i_rc!=0) { rc=BERR_TRACE(NEXUS_NOT_SUPPORTED); goto err_position_iframe;}
226
227    NEXUS_P_FilePlay_ConvertPosition(bp_info.index_entrysize, &i_frame_position, pPosition);
228    BNAV_Player_Close(bcm_player);
229    return NEXUS_SUCCESS;
230
231err_position_iframe:
232err_find_iframe:
233err_find_index:
234    BNAV_Player_Close(bcm_player);
235err_player:
236    return rc;
237}
238
239void
240NEXUS_FilePlayOffset_GetDefaultSettings(NEXUS_FilePlayOffset_Settings *settings)
241{
242    BKNI_Memset(settings, 0, sizeof(*settings));
243    settings->dataOffset = 0;
244    settings->indexOffset = 0;
245    return;
246}
247
248typedef struct NEXUS_FilePlayOffset {
249    struct NEXUS_FilePlay  parent; /* must be first */
250    NEXUS_FilePlayHandle  original;
251} NEXUS_FilePlayOffset;
252
253static void
254NEXUS_P_FilePlayOffset_Close(struct NEXUS_FilePlay *file_)
255{
256    NEXUS_FilePlayOffset *file = (NEXUS_FilePlayOffset *)file_;
257    bfile_read_offset_detach(file->parent.file.data);
258    if(file->parent.file.index) {
259        bfile_read_offset_detach(file->parent.file.index);
260    }
261    BKNI_Free(file);
262    return;
263}
264
265NEXUS_FilePlayHandle
266NEXUS_FilePlayOffset_Open( NEXUS_FilePlayHandle file, const NEXUS_FilePlayOffset_Settings *settings)
267{
268    NEXUS_FilePlayOffset *fileOffset;
269
270    BDBG_ASSERT(file);
271    BDBG_ASSERT(settings);
272    BDBG_ASSERT(file->file.data);
273    fileOffset = BKNI_Malloc(sizeof(*fileOffset));
274    if(fileOffset==NULL) {(void)BERR_TRACE(NEXUS_OUT_OF_SYSTEM_MEMORY);goto err_alloc;}
275    fileOffset->parent.file.index = NULL;
276    fileOffset->parent.file.data = bfile_read_offset_attach(file->file.data, -settings->dataOffset);
277    if(fileOffset->parent.file.data==NULL) {(void)BERR_TRACE(NEXUS_NOT_SUPPORTED);goto err_data;}
278    if(file->file.index) {
279        fileOffset->parent.file.index = bfile_read_offset_attach(file->file.index, -settings->indexOffset);
280        if(fileOffset->parent.file.index==NULL) {(void)BERR_TRACE(NEXUS_NOT_SUPPORTED);goto err_index;}
281    }
282    fileOffset->parent.file.close = NEXUS_P_FilePlayOffset_Close;
283    fileOffset->original = file;
284    return &fileOffset->parent;
285
286err_index:
287    bfile_read_offset_detach(file->file.data);
288err_data:
289    BKNI_Free(fileOffset);
290err_alloc:
291    return NULL;
292}
293
294void NEXUS_MuxFile_Close(NEXUS_MuxFileHandle file)
295{
296    file->close(&file->mux);
297    return;
298}
299
300NEXUS_MuxFileHandle NEXUS_MuxFile_OpenPosix( const char *fileName)
301{
302    struct bfile_io_mux_posix *file;
303    NEXUS_Error rc;
304
305    file = BKNI_Malloc(sizeof(*file));
306    if(!file) {rc=BERR_TRACE(BERR_OUT_OF_SYSTEM_MEMORY);goto err_alloc;}
307
308    rc = b_file_io_mux_posix_open(file, fileName, 0, false); /* no DIRECT_IO */
309    if(rc!=NEXUS_SUCCESS) {rc=BERR_TRACE(rc);goto err_open;}
310
311    return &file->self;
312
313err_open:
314    BKNI_Free(file);
315err_alloc:
316    return NULL;
317}
318
319
Note: See TracBrowser for help on using the repository browser.