Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc. 3 : * 4 : * Author: Guillaume Roguez <Guillaume.Roguez@savoirfairelinux.com> 5 : * 6 : * This program is free software; you can redistribute it and/or modify 7 : * it under the terms of the GNU General Public License as published by 8 : * the Free Software Foundation; either version 3 of the License, or 9 : * (at your option) any later version. 10 : * 11 : * This program is distributed in the hope that it will be useful, 12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 : * GNU General Public License for more details. 15 : * 16 : * You should have received a copy of the GNU General Public License 17 : * along with this program; if not, write to the Free Software 18 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 : */ 20 : 21 : #include "libav_deps.h" // MUST BE INCLUDED FIRST 22 : #include "media_io_handle.h" 23 : 24 : namespace jami { 25 : 26 994 : MediaIOHandle::MediaIOHandle(std::size_t buffer_size, 27 : bool writeable, 28 : io_readcallback read_cb, 29 : io_writecallback write_cb, 30 : io_seekcallback seek_cb, 31 994 : void* opaque) 32 994 : : ctx_(0) 33 : 34 : { 35 : /* FFmpeg doesn't alloc the buffer for the first time, but it does free and 36 : * alloc it afterwards. 37 : * Don't directly use malloc because av_malloc is optimized for memory alignment. 38 : */ 39 994 : auto buf = static_cast<uint8_t*>(av_malloc(buffer_size)); 40 994 : ctx_ = avio_alloc_context(buf, buffer_size, writeable, opaque, read_cb, write_cb, seek_cb); 41 994 : ctx_->max_packet_size = buffer_size; 42 994 : } 43 : 44 994 : MediaIOHandle::~MediaIOHandle() 45 : { 46 994 : av_free(ctx_->buffer); 47 994 : av_free(ctx_); 48 994 : } 49 : 50 : } // namespace jami