1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18 /**
19 * @file pv_comms_io_data_buffer.cpp
20 * @brief Media buffer to hold source data from Media Input modules and call
21 * writeComplete to release source data memory back to media input modules.
22 */
23
24 #ifndef PVMI_MIO_COMM_DATA_BUFFER_H_INCLUDED
25 #include "pvmi_mio_comm_data_buffer.h"
26 #endif
27 #ifndef PVMF_MEDIA_DATA_IMPL_H_INCLUDED
28 #include "pvmf_media_data_impl.h"
29 #endif
30 #ifndef OSCL_SHARED_PTR_H_INCLUDED
31 #include "oscl_shared_ptr.h"
32 #endif
33 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED
34 #include "pvmf_simple_media_buffer.h"
35 #endif
36
PvmiMIOCommDataBufferCleanup(Oscl_DefAlloc * in_gen_alloc,PvmiMediaTransfer * aMediaInput,PVMFCommandId aCmdId,OsclAny * aContext)37 PvmiMIOCommDataBufferCleanup::PvmiMIOCommDataBufferCleanup(Oscl_DefAlloc* in_gen_alloc,
38 PvmiMediaTransfer* aMediaInput,
39 PVMFCommandId aCmdId,
40 OsclAny* aContext)
41 : gen_alloc(in_gen_alloc),
42 iMediaInput(aMediaInput),
43 iCmdId(aCmdId),
44 iContext(aContext)
45 {
46 iLogger = PVLogger::GetLoggerObject("PvmiMIOCommDataBufferCleanup");
47 }
48
destruct_and_dealloc(OsclAny * ptr)49 void PvmiMIOCommDataBufferCleanup::destruct_and_dealloc(OsclAny* ptr)
50 {
51 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE,
52 (0, "PVPvmiMIOCommDataBufferCleanup::destruct_and_dealloc: iCmdId=%d", iCmdId));
53
54 if (!ptr)
55 return;
56
57 if (iMediaInput)
58 iMediaInput->writeComplete(PVMFSuccess, iCmdId, iContext);
59
60 if (!gen_alloc)
61 {
62 OsclMemAllocator my_alloc;
63 my_alloc.deallocate(ptr);
64 }
65 else
66 {
67 gen_alloc->deallocate(ptr);
68 }
69 }
70
PvmiMIOCommDataBufferAlloc(Oscl_DefAlloc * opt_gen_alloc)71 PvmiMIOCommDataBufferAlloc::PvmiMIOCommDataBufferAlloc(Oscl_DefAlloc* opt_gen_alloc)
72 : gen_alloc(opt_gen_alloc)
73 {
74 iLogger = PVLogger::GetLoggerObject("PvmiMIOCommDataBufferAlloc");
75 }
76
allocate(PvmiMediaTransfer * aMediaInput,uint8 * aData,uint32 aDataLength,PVMFCommandId aCmdId,OsclAny * aContext)77 OsclSharedPtr<PVMFMediaDataImpl> PvmiMIOCommDataBufferAlloc::allocate(PvmiMediaTransfer* aMediaInput,
78 uint8* aData,
79 uint32 aDataLength,
80 PVMFCommandId aCmdId,
81 OsclAny* aContext)
82 {
83 PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE,
84 (0, "PvmiMIOCommDataBufferAlloc::allocate: aMediaInput=0x%x, aData=0x%x, aDataLength=%d, aCmdId=%d, aContext=0x%x",
85 aMediaInput, aData, aDataLength, aCmdId, aContext));
86
87 uint aligned_refcnt_size;
88 uint aligned_class_size = oscl_mem_aligned_size(sizeof(PVMFSimpleMediaBuffer));
89 OsclRefCounter* my_refcnt;
90 uint8* my_ptr;
91
92 aligned_refcnt_size = oscl_mem_aligned_size(sizeof(OsclRefCounterDA));
93 uint aligned_cleanup_size = oscl_mem_aligned_size(sizeof(PvmiMIOCommDataBufferCleanup));
94 if (!gen_alloc)
95 {
96 OsclMemAllocator my_alloc;
97 my_ptr = (uint8*) my_alloc.allocate(aligned_refcnt_size + aligned_cleanup_size + aligned_class_size);
98 }
99 else
100 {
101 my_ptr = (uint8*) gen_alloc->allocate(aligned_refcnt_size + aligned_cleanup_size + aligned_class_size);
102 }
103
104 PvmiMIOCommDataBufferCleanup* cleanup_ptr =
105 OSCL_PLACEMENT_NEW(my_ptr + aligned_refcnt_size, PvmiMIOCommDataBufferCleanup(gen_alloc, aMediaInput, aCmdId, aContext));
106 my_refcnt = OSCL_PLACEMENT_NEW(my_ptr, OsclRefCounterDA(my_ptr, cleanup_ptr));
107 my_ptr += aligned_refcnt_size + aligned_cleanup_size;
108
109 PVMFMediaDataImpl* media_data_ptr = OSCL_PLACEMENT_NEW(my_ptr, PVMFSimpleMediaBuffer((OsclAny*)aData, aDataLength, my_refcnt));
110 OsclSharedPtr<PVMFMediaDataImpl> shared_media_data(media_data_ptr, my_refcnt);
111 return shared_media_data;
112 }
113
114
115
116