[vlmc-devel] [PATCH 2/5] VLCSource, VmemRenderer: Use const uint8_t* snapshot

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Apr 12 15:43:58 CEST 2016


On 04/12/2016 03:24 PM, yikei lu wrote:
> So you meant copying the value of the pointer to VLCSource and use an
> unique_ptr in VmemRenderer?
>
> 2016-04-12 22:21 GMT+09:00 yikei lu <luyikei.qmltu at gmail.com>:
>> Oh sorry I might have misread this...
>>
>> 2016-04-12 22:20 GMT+09:00 yikei lu <luyikei.qmltu at gmail.com>:
>>> well it is used in VLCSource so there will be a problem if we use unique_ptr
>>>
>>> 2016-04-12 22:17 GMT+09:00 Hugo Beauzée-Luyssen <hugo at beauzee.fr>:
>>>> On 04/12/2016 03:09 PM, Yikai Lu wrote:
>>>>>
>>>>> ---
>>>>>    src/Backend/VLC/VLCSource.h         | 2 +-
>>>>>    src/Backend/VLC/VLCVmemRenderer.cpp | 2 +-
>>>>>    src/Backend/VLC/VLCVmemRenderer.h   | 2 +-
>>>>>    3 files changed, 3 insertions(+), 3 deletions(-)
>>>>>
>>>>> diff --git a/src/Backend/VLC/VLCSource.h b/src/Backend/VLC/VLCSource.h
>>>>> index 10a7d08..b2262df 100644
>>>>> --- a/src/Backend/VLC/VLCSource.h
>>>>> +++ b/src/Backend/VLC/VLCSource.h
>>>>> @@ -69,7 +69,7 @@ private:
>>>>>        unsigned int                m_nbVideoTracks;
>>>>>        unsigned int                m_nbAudioTracks;
>>>>>        int64_t                     m_length; //in milliseconds.
>>>>> -    uint8_t*                    m_snapshot;
>>>>> +    const uint8_t*              m_snapshot;
>>>>>        bool                        m_isParsed;
>>>>>        int64_t                     m_nbFrames;
>>>>>    };
>>>>> diff --git a/src/Backend/VLC/VLCVmemRenderer.cpp
>>>>> b/src/Backend/VLC/VLCVmemRenderer.cpp
>>>>> index d062bbe..8312ecd 100644
>>>>> --- a/src/Backend/VLC/VLCVmemRenderer.cpp
>>>>> +++ b/src/Backend/VLC/VLCVmemRenderer.cpp
>>>>> @@ -68,7 +68,7 @@ VmemRenderer::mediaPlayer()
>>>>>        return m_mediaPlayer;
>>>>>    }
>>>>>
>>>>> -uint8_t*
>>>>> +const uint8_t*
>>>>>    VmemRenderer::waitSnapshot()
>>>>>    {
>>>>>        QMutexLocker lock( &m_mutex );
>>>>> diff --git a/src/Backend/VLC/VLCVmemRenderer.h
>>>>> b/src/Backend/VLC/VLCVmemRenderer.h
>>>>> index 89b105d..b7a765e 100644
>>>>> --- a/src/Backend/VLC/VLCVmemRenderer.h
>>>>> +++ b/src/Backend/VLC/VLCVmemRenderer.h
>>>>> @@ -47,7 +47,7 @@ public:
>>>>>         *  the caller.
>>>>>         * @return
>>>>>         */
>>>>> -    uint8_t *waitSnapshot();
>>>>> +    const uint8_t *waitSnapshot();
>>>>>
>>>>>    private:
>>>>>        void*    vmemLock( void **planes );
>>>>>
>>>> Oh, I meant use uint8_t* as the exposed return value (which means that the
>>>> called doesn't own this value, and that it's bound to the lifetime of the
>>>> VmemRenderer, or shorter), and use a unique_ptr internally, so it gets
>>>> automatically released when the VmemRenderer gets deleted.
>>>> _______________________________________________
>>>> Vlmc-devel mailing list
>>>> Vlmc-devel at videolan.org
>>>> https://mailman.videolan.org/listinfo/vlmc-devel
> _______________________________________________
> Vlmc-devel mailing list
> Vlmc-devel at videolan.org
> https://mailman.videolan.org/listinfo/vlmc-devel
>

Well, it depends how waitSnapshot() return value is used.
If we expect only one snapshot to be present at all time, use 
unique_ptr, do not even store it in VmemRenderer. Just return a 
unique_ptr, so it now belongs to the caller.
If we expect the VmemRenderer and the caller to use the snapshot 
simultaneously (this sounds like a bad idea, but let's assume that's the 
case, for the sake of the example), then use a shared_ptr
If the caller only needs to read from the snapshot but the snapshot is 
solely owned by the VmemRenderer, then store the snapshot as a member 
unique_ptr, and return a const uint8_t* from waitSnapshot()

I hope this explanation was a bit clearer :)


More information about the Vlmc-devel mailing list