summaryrefslogtreecommitdiffstats
path: root/libvideoeditor/osal/src/M4OSA_FileReader.c
blob: 40a72f5c7cf27316299c8e1e4b36d6423cb0adb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
************************************************************************
 * @file         M4OSA_FileReader.c
 * @author       Cedric Lecoutre (cedric.lecoutre@philips.com)
 *               Laurent Fay (laurent.fay@philips.com)
 * @par Org:     Philips Digital Systems Laboratories - Paris (PDSL-P)
 * @brief        File reader for Android
 * @note         This file implements functions to read a file.
 ************************************************************************
*/


#include "M4OSA_Debug.h"
#include "M4OSA_FileCommon_priv.h"
#include "M4OSA_FileReader.h"
#include "M4OSA_FileReader_priv.h"
#include "M4OSA_Memory.h"

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
#include "M4OSA_Semaphore.h"
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */


/**
************************************************************************
* @brief      This function opens the provided URL and returns its context.
*             If an error occured, the context is set to NULL.
* @param      context: (OUT) Context of the core file reader
* @param      url: (IN) URL of the input file
* @param      fileModeAccess: (IN) File mode access
* @return     M4NO_ERROR: there is no error
* @return     M4ERR_PARAMETER: at least one parameter is NULL
* @return     M4ERR_ALLOC: there is no more memory available
* @return     M4ERR_NOT_IMPLEMENTED: the URL does not match with the supported
*             file
* @return     M4ERR_FILE_NOT_FOUND: the file cannot be found
* @return     M4ERR_FILE_LOCKED: the file is locked by an other
*             application/process
* @return     M4ERR_FILE_BAD_MODE_ACCESS: the file mode access is not correct
************************************************************************
*/
M4OSA_ERR M4OSA_fileReadOpen(M4OSA_Context* pContext, M4OSA_Void* pFileDescriptor,
                             M4OSA_UInt32 fileModeAccess)
{
    M4OSA_TRACE1_3("M4OSA_fileReadOpen : pC = 0x%p  fd = 0x%p  mode = %lu",
                                     pContext, pFileDescriptor, fileModeAccess);

    return M4OSA_fileCommonOpen(M4OSA_FILE_READER, pContext,
                                               pFileDescriptor, fileModeAccess);
}

/**
************************************************************************
* @brief      This function reads the 'size' bytes in the core file reader
*             (selected by its 'context') and writes the data to the 'data'
*             pointer.
* @note       If 'size' byte cannot be read in the core file reader, 'size'
*             parameter is updated to match the correct
* @note       number of read bytes.
* @param      context: (IN/OUT) Context of the core file reader
* @param      buffer: (OUT) Data pointer of the read data
* @param      size: (IN/OUT) Size of the data to read (in bytes)
* @return     M4NO_ERROR: there is no error
* @return     M4ERR_PARAMETER: at least one parameter is NULL
* @return     M4ERR_BAD_CONTEXT: provided context is not a valid one
* @return     M4ERR_ALLOC: there is no more memory available
* @return     M4WAR_NO_DATA_YET: there is no enough data to fill the 'data'
*             buffer, so the size parameter has been updated.
************************************************************************
*/
M4OSA_ERR M4OSA_fileReadData(M4OSA_Context pContext, M4OSA_MemAddr8 data,
                                                            M4OSA_UInt32* pSize)
{
    M4OSA_FileContext* pFileContext = pContext;
    M4OSA_ERR    err = M4NO_ERROR;
    M4OSA_Int32    uiSizeRead;

    M4OSA_TRACE2_2("M4OSA_fileReadData : data = 0x%p  size = %lu",
                                    data, (M4OSA_NULL != pSize) ? (*pSize) : 0);

    M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
                                  "M4OSA_fileReadData: pContext is M4OSA_NULL");
    M4OSA_DEBUG_IF2(M4OSA_NULL == data, M4ERR_PARAMETER,
                                      "M4OSA_fileReadData: data is M4OSA_NULL");
    M4OSA_DEBUG_IF2(M4OSA_NULL == pSize, M4ERR_PARAMETER,
                                     "M4OSA_fileReadData: pSize is M4OSA_NULL");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context,
      M4ERR_BAD_CONTEXT, "M4OSA_fileReadData: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    if(M4OSA_kDescRWAccess == pFileContext->m_DescrModeAccess) /* read write */
    {
        uiSizeRead = fread(data, sizeof(M4OSA_Char), *pSize,
                                                       pFileContext->file_desc);
        if(-1 == uiSizeRead)
        {
            /* handle is invalid, or the file is not open for reading, or the file is locked */
            *pSize = 0;
            err = M4ERR_BAD_CONTEXT;
        }
        else
        {
            pFileContext->read_position = pFileContext->read_position + uiSizeRead;
            if ((M4OSA_UInt32)uiSizeRead < *pSize)
            {
                *pSize = uiSizeRead;
                /* This is the end of file */
                pFileContext->b_is_end_of_file = M4OSA_TRUE;
                err = M4WAR_NO_DATA_YET;
            }
            else
            {
                *pSize = uiSizeRead;
            }
        }

        return err;
    }

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    if(pFileContext->current_seek != SeekRead)
    {
        /* fseek to the last read position */
        err = M4OSA_fileCommonSeek(pContext, M4OSA_kFileSeekBeginning,
                                                &(pFileContext->read_position));
        if(M4OSA_ERR_IS_ERROR(err))
        {
            M4OSA_DEBUG(err, "M4OSA_fileReadData: M4OSA_fileCommonSeek");

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            return err;
        }

        pFileContext->current_seek = SeekRead;
    }

    /* Read data */
    uiSizeRead = fread(data, sizeof(M4OSA_Char), *pSize,
                                                       pFileContext->file_desc);
    if(-1 == uiSizeRead)
    {
        /* handle is invalid, or the file is not open for reading,
         or the file is locked */
        *pSize = 0;
        err = M4ERR_BAD_CONTEXT;
    }
    else
    {
        pFileContext->read_position = pFileContext->read_position + uiSizeRead;
        if ((M4OSA_UInt32)uiSizeRead < *pSize)
        {
            *pSize = uiSizeRead;

            /* This is the end of file */
            pFileContext->b_is_end_of_file = M4OSA_TRUE;

            err = M4WAR_NO_DATA_YET;
        }
        else
        {
            *pSize = uiSizeRead;
        }
    }

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */


    return err;
}


/**
************************************************************************
 * @brief      This function seeks at the provided position in the core file
 *             reader (selected by its 'context'). The position is related to
 *             the seekMode parameter it can be either from the beginning, from
 *             the end or from the current postion. To support large file
 *             access (more than 2GBytes), the position is provided on a 64
 *             bits.
 * @note       If this function returns an error the current position pointer
 *             in the file must not change. Else the current
 *             position pointer must be updated.
 * @param      context: (IN/OUT) Context of the core file reader
 * @param      seekMode: (IN) Seek access mode
 * @param      position: (IN/OUT) Position in the file
 * @return     M4NO_ERROR: there is no error
 * @return     M4ERR_PARAMETER: at least one parameter is NULL
 * @return     M4ERR_BAD_CONTEXT: provided context is not a valid one
 * @return     M4ERR_ALLOC: there is no more memory available
 * @return     M4ERR_FILE_INVALID_POSITION: the position cannot be reached
 ************************************************************************
*/

M4OSA_ERR M4OSA_fileReadSeek(M4OSA_Context pContext, M4OSA_FileSeekAccessMode seekMode,
                             M4OSA_FilePosition* pPosition)
{
    M4OSA_FileContext* pFileContext = (M4OSA_FileContext*)pContext;
    M4OSA_ERR err;

    M4OSA_TRACE2_2("M4OSA_fileReadSeek : mode = %d  pos = %lu", seekMode,
                                  (pPosition != M4OSA_NULL) ? (*pPosition) : 0);

    M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
                                  "M4OSA_fileReadSeek: pContext is M4OSA_NULL");
    M4OSA_DEBUG_IF2(0 == seekMode, M4ERR_PARAMETER,
                                           "M4OSA_fileReadSeek: seekMode is 0");
    M4OSA_DEBUG_IF2(M4OSA_NULL == pPosition, M4ERR_PARAMETER,
                                 "M4OSA_fileReadSeek: pPosition is M4OSA_NULL");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context,
      M4ERR_BAD_CONTEXT, "M4OSA_fileReadSeek: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    if (M4OSA_kDescRWAccess == pFileContext->m_DescrModeAccess)
    {
         M4OSA_UInt32    SeekModeOption;
         /* Go to the desired position */
        if (M4OSA_kFileSeekBeginning == seekMode)
        {
            SeekModeOption = SEEK_SET;
        }
        else if (M4OSA_kFileSeekEnd == seekMode)
        {
            SeekModeOption = SEEK_END;
        }
        else if (M4OSA_kFileSeekCurrent == seekMode)
        {
            SeekModeOption = SEEK_CUR;
        }
        else
        {
            M4OSA_TRACE1_0("M4OSA_fileReadSeek: END WITH ERROR !!! (CONVERION ERROR FOR THE SEEK MODE)");
            return M4ERR_PARAMETER;
        }

        /**
         * Go to the desired position */
        err = fseek(pFileContext->file_desc, *pPosition, SeekModeOption);
        if(err != 0)
        {
            /* converts the error to PSW format*/
            err=((M4OSA_UInt32)(M4_ERR)<<30)+(((M4OSA_FILE_WRITER)&0x003FFF)<<16)+(M4OSA_Int16)(err);
            M4OSA_TRACE1_1("M4OSA_FileReadSeek error:%x",err);
        }
        else
        {
            return M4NO_ERROR;
        }

        /* Return without error */
        return err;
    }


#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    if(pFileContext->current_seek != SeekRead)
    {

        /* fseek to the last read position */
        err = M4OSA_fileCommonSeek(pContext, M4OSA_kFileSeekBeginning,
                                                &(pFileContext->read_position));
        if(M4OSA_ERR_IS_ERROR(err))
        {
            M4OSA_DEBUG(err, "M4OSA_fileReadData: M4OSA_fileCommonSeek");

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            return err;
        }

        pFileContext->current_seek = SeekRead;
    }

    err = M4OSA_fileCommonSeek(pContext, seekMode, pPosition);
    if(M4OSA_ERR_IS_ERROR(err))
    {
        M4OSA_DEBUG(err, "M4OSA_fileReadData: M4OSA_fileCommonSeek");
    }
    else
    {
        pFileContext->read_position = *pPosition;
    }

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    return err;
}


/**
 ************************************************************************
 * @brief      This function asks the core file reader to close the file
 *             (associated to the context).
 * @note       The context of the core file reader is freed.
 * @param      pContext: (IN/OUT) Context of the core file reader
 * @return     M4NO_ERROR: there is no error
 * @return     M4ERR_PARAMETER: at least one parameter is NULL
 * @return     M4ERR_BAD_CONTEXT: provided context is not a valid one
 * @return     M4ERR_ALLOC: there is no more memory available
 ************************************************************************
*/
M4OSA_ERR M4OSA_fileReadClose(M4OSA_Context pContext)
{
    M4OSA_FileContext* pFileContext = (M4OSA_FileContext*)pContext;

    M4OSA_TRACE1_1("M4OSA_fileReadClose : pC = 0x%p", pContext);

    M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
                                 "M4OSA_fileReadClose: pContext is M4OSA_NULL");

    if(M4OSA_FILE_WRITER == pFileContext->coreID_write)
    {
        return M4NO_ERROR;
    }

    return M4OSA_fileCommonClose(M4OSA_FILE_READER, pContext);
}




/**
 ************************************************************************
 * @brief      This function asks the core file reader to return the value
 *             associated with the optionID. The caller is responsible for
 *             allocating/de-allocating the memory of the value field.
 * @note       'value' must be cast according to the type related to the
 *             optionID As the caller is responsible for
 *             allocating/de-allocating the 'value' field, the callee must copy
 *             this field to its internal variable.
 * @param      pContext: (IN/OUT) Context of the core file reader
 * @param      pOptionID: (IN) ID of the option
 * @param      pOptionValue: (OUT) Value of the option
 * @return     M4NO_ERROR: there is no error
 * @return     M4ERR_PARAMETER: at least one parameter is NULL
 * @return     M4ERR_BAD_CONTEXT: provided context is not a valid one
 * @return     M4ERR_BAD_OPTION_ID: the optionID is not a valid one
 * @return     M4ERR_WRITE_ONLY: this option is a write only one
 * @return     M4ERR_NOT_IMPLEMENTED: this option is not implemented
 ************************************************************************
*/
M4OSA_ERR M4OSA_fileReadGetOption(M4OSA_Context pContext, M4OSA_FileReadOptionID optionID,
                                  M4OSA_DataOption* pOptionValue)
{
    M4OSA_FileContext* pFileContext = pContext;

    M4OSA_TRACE2_1("M4OSA_fileReadGetOption : option = 0x%x", optionID);

    M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
                             "M4OSA_fileReadGetOption: pContext is M4OSA_NULL");
    M4OSA_DEBUG_IF2(optionID == 0, M4ERR_PARAMETER,
                                      "M4OSA_fileReadGetOption: optionID is 0");
    M4OSA_DEBUG_IF2(M4OSA_NULL == pOptionValue, M4ERR_PARAMETER,
                         "M4OSA_fileReadGetOption: pOptionValue is M4OSA_NULL");

    M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_COREID(optionID, M4OSA_FILE_READER),
                                M4ERR_BAD_OPTION_ID, "M4OSA_fileReadGetOption");
    M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_READABLE(optionID),
                                   M4ERR_WRITE_ONLY, "M4OSA_fileReadGetOption");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context,
                                  M4ERR_BAD_CONTEXT,
                                  "M4OSA_fileReadGetOption: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    switch(optionID)
    {
#if(M4OSA_OPTIONID_FILE_READ_GET_FILE_POSITION == M4OSA_TRUE)
    case M4OSA_kFileReadGetFilePosition:
        {
            M4OSA_FilePosition* pPosition = (M4OSA_FilePosition*)pOptionValue;

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            *pPosition = pFileContext->read_position;

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            return M4NO_ERROR;
        }
#endif /*M4OSA_OPTIONID_FILE_READ_GET_FILE_POSITION*/

#if(M4OSA_OPTIONID_FILE_READ_IS_EOF == M4OSA_TRUE)
    case M4OSA_kFileReadIsEOF:
        {
            M4OSA_Bool* bIsEndOfFile = (M4OSA_Bool*)pOptionValue;

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            *bIsEndOfFile = pFileContext->b_is_end_of_file;

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            return M4NO_ERROR;
        }
#endif /*M4OSA_OPTIONID_FILE_READ_IS_EOF*/


#if(M4OSA_OPTIONID_FILE_READ_GET_FILE_SIZE == M4OSA_TRUE)
    case M4OSA_kFileReadGetFileSize:
        {
            M4OSA_FilePosition* pPosition = (M4OSA_FilePosition*)pOptionValue;
            M4OSA_Int32 iSavePos    = 0;
            M4OSA_Int32 iSize        = 0;

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphoreWait(pFileContext->semaphore_context, M4OSA_WAIT_FOREVER);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */
            /**
            * Bugfix: update the file size.
            * When a file is in read mode, may be another application is writing in.
            * So, we have to update the file size */
            iSavePos = ftell(pFileContext->file_desc);            /*1- Check the first position */
            fseek(pFileContext->file_desc, 0, SEEK_END);        /*2- Go to the end of the file */
            iSize = ftell(pFileContext->file_desc);                /*3- Check the file size*/
            fseek(pFileContext->file_desc, iSavePos, SEEK_SET);    /*4- go to the first position*/
            pFileContext->file_size = iSize;

            *pPosition = pFileContext->file_size;

#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
            M4OSA_semaphorePost(pFileContext->semaphore_context);
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

            return M4NO_ERROR;
        }
#endif /*M4OSA_OPTIONID_FILE_READ_GET_FILE_SIZE*/

#if(M4OSA_OPTIONID_FILE_READ_GET_FILE_ATTRIBUTE == M4OSA_TRUE)
    case M4OSA_kFileReadGetFileAttribute:
        {
            return M4OSA_fileCommonGetAttribute(pContext,
                                            (M4OSA_FileAttribute*)pOptionValue);
        }
#endif /*M4OSA_OPTIONID_FILE_READ_GET_FILE_ATTRIBUTE*/

#if(M4OSA_OPTIONID_FILE_READ_GET_URL == M4OSA_TRUE)
    case M4OSA_kFileReadGetURL:
        {
            return M4OSA_fileCommonGetURL(pContext, (M4OSA_Char**)pOptionValue);
        }
#endif /*M4OSA_OPTIONID_FILE_READ_GET_URL*/

        case M4OSA_kFileReadLockMode:
        {
            *(M4OSA_UInt32*)pOptionValue = pFileContext->m_uiLockMode;
            return M4NO_ERROR;
        }
    }

    M4OSA_DEBUG(M4ERR_NOT_IMPLEMENTED, "M4OSA_fileReadGetOption");

    return M4ERR_NOT_IMPLEMENTED;
}

/**
 ************************************************************************
 * @fn         M4OSA_ERR M4OSA_fileReadSetOption (M4OSA_Context context,
 *                       M4OSA_OptionID optionID, M4OSA_DataOption optionValue))
 * @brief      This function asks the core file reader to set the value associated with the optionID.
 *             The caller is responsible for allocating/de-allocating the memory of the value field.
 * @note       As the caller is responsible for allocating/de-allocating the 'value' field, the callee must copy this field
 *             to its internal variable.
 * @param      pContext: (IN/OUT) Context of the core file reader
 * @param      optionID: (IN) ID of the option
 * @param      value: (IN) Value of the option
 * @return     M4NO_ERROR: there is no error
 * @return     M4ERR_PARAMETER: at least one parameter is NULL
 * @return     M4ERR_BAD_CONTEXT: provided context is not a valid one
 * @return     M4ERR_BAD_OPTION_ID: the optionID is not a valid one
 * @return     M4ERR_READ_ONLY: this option is a read only one
 * @return     M4ERR_NOT_IMPLEMENTED: this option is not implemented
 ************************************************************************
*/
M4OSA_ERR M4OSA_fileReadSetOption(M4OSA_Context pContext,
                                  M4OSA_FileReadOptionID optionID,
                                  M4OSA_DataOption optionValue)
{
    M4OSA_FileContext* pFileContext = pContext;

    M4OSA_TRACE2_1("M4OSA_fileReadSetOption : option = 0x%x", optionID);

    M4OSA_DEBUG_IF2(M4OSA_NULL == pContext, M4ERR_PARAMETER,
                             "M4OSA_fileReadSetOption: pContext is M4OSA_NULL");
    M4OSA_DEBUG_IF2(0 == optionID, M4ERR_PARAMETER,
                                                     "M4OSA_fileReadSetOption");
    M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_COREID(optionID, M4OSA_FILE_READER),
                                M4ERR_BAD_OPTION_ID, "M4OSA_fileReadSetOption");

    M4OSA_DEBUG_IF2(!M4OSA_OPTION_ID_IS_WRITABLE(optionID),
                                    M4ERR_READ_ONLY, "M4OSA_fileReadSetOption");
#ifdef M4OSA_FILE_BLOCK_WITH_SEMAPHORE
    M4OSA_DEBUG_IF2(M4OSA_NULL == pFileContext->semaphore_context,
                                  M4ERR_BAD_CONTEXT,
                                  "M4OSA_fileReadSetOption: semaphore_context is M4OSA_NULL");
#endif /* M4OSA_FILE_BLOCK_WITH_SEMAPHORE */

    switch(optionID)
    {
        case M4OSA_kFileReadLockMode:
        {
            pFileContext->m_uiLockMode= (M4OSA_UInt32)*(M4OSA_UInt32*)optionValue;
            return M4NO_ERROR;
        }
        default:
            M4OSA_DEBUG(M4ERR_NOT_IMPLEMENTED, "M4OSA_fileReadSetOption");
            return M4ERR_NOT_IMPLEMENTED;
    }
}