AM_ERR CInputPlayback::CreateSubGraph() { if (AM_UNLIKELY(mFilterGraph->AddFilter(mDemuxerFilter) != ME_OK)) { ERROR("Failed to add universal demuxer filter!"); return ME_ERROR; } if (AM_UNLIKELY(mFilterGraph->AddFilter(mAudioDecoder) != ME_OK)) { ERROR("Failed to add audio decoder filter!"); return ME_ERROR; } if (AM_UNLIKELY(mFilterGraph->AddFilter(mPacketAggregator) != ME_OK)) { ERROR("Failed to add PacketAggregator!"); return ME_ERROR; } if (AM_UNLIKELY(mFilterGraph->Connect( mDemuxerFilter, 0, mAudioDecoder, 0) != ME_OK)) { ERROR("Failed to connect Universal Demuxer to audio decoder!"); return ME_ERROR; } if (AM_UNLIKELY(mFilterGraph->Connect( mAudioDecoder, 0, mPacketAggregator, 0) != ME_OK)) { ERROR("Failed to connect AudioDecoder to PacketAggregator!"); return ME_ERROR; } return ME_OK; }
AM_ERR CJpegFileWriter::SetMediaSink (const char *pFileName) { const char *fileName = "/tmp/"; if (pFileName == NULL) { ERROR ("File's name should not be empty.\n"); return ME_ERROR; } /* * Currently, as the file location for different stream has not * be splitted and the speed of writing sd card is not fast, so * we need to put jpeg file into memory. * * When the file location of different stream is seperated, * remove the definition of fileName and replace fileName with * pFileName in this routine. */ if (mpFileName != NULL) { INFO ("File name: %s will be rewritten.\n", mpFileName); delete[] mpFileName; mpFileName = NULL; } if (mpCurFileName != NULL) { delete[] mpCurFileName; mpCurFileName = NULL; } if (mpTmpFileName != NULL) { delete[] mpTmpFileName; } if (AM_UNLIKELY(NULL == (mpFileName = amstrdup(fileName)))) { ERROR("Failed to duplicate file name string!"); return ME_NO_MEMORY; } mpCurFileName = new char [strlen (fileName) + 10]; if (AM_UNLIKELY(mpCurFileName == NULL)) { ERROR ("Failed to allocate memory for cur name.\n"); return ME_NO_MEMORY; } else { memset(mpCurFileName, 0, sizeof(strlen(fileName) + 10)); } mpTmpFileName = new char [strlen(fileName) + 10]; if (AM_UNLIKELY(mpTmpFileName == NULL)) { ERROR ("Failed to allocate memory for cur name.\n"); return ME_NO_MEMORY; } else { memset(mpTmpFileName, 0, sizeof(strlen(fileName) + 10)); snprintf (mpTmpFileName, strlen(mpFileName) + 10, "%s_%s.jpeg", mpFileName, "tmp"); } INFO ("File's name: %s\n", mpFileName); return CreateSymbolLinks (); }
inline AM_ERR CMp4Muxer::OnEventData (CPacket *packet) { if (packet->GetAttr() == CPacket::AM_PAYLOAD_ATTR_VIDEO) { /* Video Data */ if (AM_UNLIKELY (mbIsFirstVideo)) { /* first frame must be video frame, * and the first video frame must be I frame */ mbAudioEnable = true; mbIsFirstVideo = !(packet->GetFrameType() == IDR_FRAME && mbIsFirstAudio); AM_ASSERT (packet->GetFrameType () == IDR_FRAME && mbIsFirstAudio); } AM_ENSURE_OK_( mpMP4Builder->put_VideoData(packet->GetDataPtr(), packet->GetDataSize(), packet->GetPTS(), mBufferdUsrSEI)); if (mBufferdUsrSEI) { mBufferdUsrSEI->Release(); mBufferdUsrSEI = NULL; } mLastVideoPTS = packet->GetPTS(); } else if (packet->GetAttr () == CPacket::AM_PAYLOAD_ATTR_AUDIO) { /* Audio Data */ if (AM_UNLIKELY(!mbAudioEnable)) { INFO ("Video frame has not been received, " "drop current audio packet: %llu", packet->GetPTS()); return ME_OK; } if (AM_UNLIKELY(mpMP4Builder->put_AudioData(packet->GetDataPtr(), packet->GetDataSize(), packet->GetFrameCount()) == ME_TOO_MANY)) { NOTICE("The file size is too larger, stop stream engine!"); PostEngineMsg(IEngine::MSG_EOS); return ME_OK; } } else if (packet->GetAttr () == CPacket::AM_PAYLOAD_ATTR_SEI) { packet->AddRef(); mBufferdUsrSEI = packet; } else { NOTICE ("Currently, mp4 muxer just support audio and video stream.\n"); return ME_ERROR; } return ME_OK; }
void am_print(const char *_format, ...) { init(); if (AM_UNLIKELY(AM_LOG_LEVEL_PRINT <= logLevel)) { char text[2*1024] = {0}; char format[2*1024] = {0}; va_list vlist; snprintf(format, sizeof(format), "%s", _format); if (format[strlen(format) - 1] == '\n') { //Eat trailing \n, \n will be added automatically! format[strlen(format) - 1] = '\0'; } if (logTarget == AM_LOG_TARGET_SYSLOG) { sprintf(text, "%s", format); } else if (logTarget == AM_LOG_TARGET_FILE) { sprintf(text, "%s", format); } else { sprintf(text, B_WHITE("%s"), format); } va_start(vlist, _format); am_level_logv(NULL, AM_LOG_LEVEL_PRINT, text, vlist); va_end(vlist); } }
int main(int argc, char **argv) { if (argc < 2) { ERROR("Usage: test_amplayback mediafile1 [mediafile2 | ...]"); } else { if (AM_UNLIKELY(pipe(ctrl) < 0)) { PERROR("pipe"); } else { signal(SIGINT, sigstop); signal(SIGQUIT, sigstop); signal(SIGTERM, sigstop); g_isrunning = false; g_amplayback = new AmPlaybackStream(); if (g_amplayback && g_amplayback->init_playback_stream()) { g_amplayback->set_app_msg_callback(app_engine_callback, NULL); mainloop((const char**)&argv[1], argc - 1); } delete g_amplayback; close(CTRL_READ); close(CTRL_WRITE); } } return 0; }
const char* CRtpSessionVideo::GetVideoFps(AM_U32& fps) { char *videoFps = NULL; memset(mFrameRateStr, 0, sizeof(mFrameRateStr)); for (uint32_t i = 0; i < sizeof(gFpsList) / sizeof(CameraVinFPS); ++ i) { if (gFpsList[i].fpsValue == fps) { videoFps = (char *)gFpsList[i].fpsName; DEBUG("%u is converted to %s", fps, videoFps); break; } } if (AM_UNLIKELY(videoFps == NULL)) { if (fps != 0xffffffff) { snprintf(mFrameRateStr, sizeof(mFrameRateStr), "%.2lf", (double)(512000000/fps)); videoFps = mFrameRateStr; } else { videoFps = (char *)gFpsList[0].fpsName; WARN("Invalid fps value %u, reset to auto!", fps); } } return videoFps; }
AM_ERR CTsHttpWriter::SetMediaSink (const char *pDestURL) { if (inherited::SetMediaSink ("/tmp/ts_file") != ME_OK) { ERROR ("Failed to set media sink for parent!"); return ME_ERROR; } if (pDestURL == NULL) { ERROR ("Destination url should not be empty.\n"); return ME_ERROR; } if (mpDestURL != NULL) { INFO ("Destination URL: %s will be rewrited.\n", mpDestURL); delete[] mpDestURL; mpDestURL = NULL; } mpDestURL = amstrdup(pDestURL); if (AM_UNLIKELY(!mpDestURL)) { ERROR("Failed to duplicate destination url!"); return ME_NO_MEMORY; } return ME_OK; }
AM_ERR CMp4Builder::put_AudioData(AM_U8* pData, AM_UINT dataSize, AM_U32 frameCount) { AM_U8 *pFrameStart; AM_U32 frameSize; FeedStreamData(pData, dataSize, frameCount); while (GetOneFrame (&pFrameStart, &frameSize)) { AM_UINT chunk_offset = mCurPos; AdtsHeader *adtsHeader = (AdtsHeader*)pFrameStart; AM_UINT header_length = sizeof(AdtsHeader); if (AM_UNLIKELY((mCurPos + frameSize + MovieBox_SIZE) > _record_info.max_filesize)) { return ME_TOO_MANY; } if (AM_UNLIKELY(frameSize < 7)) { return ME_ERROR; } if (AM_UNLIKELY(false == adtsHeader->IsSyncWordOk())) { return ME_ERROR; } if (AM_LIKELY(_audio_spec_config == 0xffff)) { _audio_spec_config = (((adtsHeader->AacAudioObjectType() << 11) | (adtsHeader->AacFrequencyIndex() << 7) | (adtsHeader->AacChannelConf() << 3)) & 0xFFF8); INFO("Audio Spec Info: 0x%04x", _audio_spec_config); } if (AM_LIKELY(adtsHeader->AacFrameNumber() == 0)) { if (adtsHeader->ProtectionAbsent() == 0) { //adts_error_check header_length += 2; } //adts_fixed_header + adts_variable_header put_buffer(pFrameStart + header_length, frameSize - header_length); } else { //Todo } UpdateAudioIdx((frameSize - header_length), chunk_offset); } return ME_OK; }
CMp4Muxer *CMp4Muxer::Create(IEngine *pEngine, bool RTPriority, int priority) { CMp4Muxer *result = new CMp4Muxer(pEngine); if (AM_UNLIKELY(result && result->Construct(RTPriority, priority) != ME_OK)) { delete result; result = NULL; } return result; }
void NetInfoIPv4::set_address(uint32_t addr) { netdev_address = addr; memset(address_string, 0, sizeof(address_string)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET, (void*)&netdev_address, address_string, INET_ADDRSTRLEN))) { PERROR("inet_ntop"); } }
void DnsIPv4::set_dns(uint32_t d) { dns = d; memset(dns_string, 0, sizeof(dns_string)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET, (void*)&dns, dns_string, INET_ADDRSTRLEN))) { PERROR("inet_ntop"); } }
AMnDIndex::AMnDIndex(const AMnDIndex &other) { rank_ = other.rank_; memcpy(dims_, other.dims_, 8*sizeof(long)); if(AM_UNLIKELY(rank_ > 8)) extras_ = new QVector<long>(*(other.extras_)); else extras_ = 0; }
void NetInfoIPv4::set_gateway(uint32_t gw) { netdev_gateway = gw; memset(gateway_string, 0, sizeof(gateway_string)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET, (void*)&netdev_gateway, gateway_string, INET_ADDRSTRLEN))) { PERROR("inet_ntop"); } }
char* NetInfoIPv6::get_gateway_string() { memset(&gateway_string, 0, sizeof(struct in6_addr)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET6, (void*)&netdev_gateway, gateway_string, INET6_ADDRSTRLEN))) { PERROR("inet_ntop"); } return gateway_string; }
AMnDIndex& AMnDIndex::operator=(const AMnDIndex& other) { if(AM_UNLIKELY(other.rank_ > 8)) { if(rank_ > 8) // already have an extras_; assign from other's. *extras_ = *(other.extras_); else // need to make an extras_ extras_ = new QVector<long>(*(other.extras_)); } // need to get rid of our extras_ ? if(AM_UNLIKELY(rank_ > 8 && other.rank_ <=8)) { delete extras_; extras_ = 0; } rank_ = other.rank(); memcpy(dims_, other.dims_, 8*sizeof(long)); return *this; }
char* DnsIPv6::get_dns_string() { memset(&dns_string, 0, sizeof(struct in6_addr)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET6, (void*)&dns, dns_string, INET6_ADDRSTRLEN))) { PERROR("inet_ntop"); } return dns_string; }
CDemuxer* CDemuxerAac::Create(AM_UINT streamid) { CDemuxerAac* result = new CDemuxerAac(streamid); if (AM_UNLIKELY(result && (ME_OK != result->Construct()))) { delete result; result = NULL; } return result; }
void NetInfoIPv4::set_netmask(uint32_t mask) { netdev_netmask = mask; memset(netmask_string, 0, sizeof(netmask_string)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET, (void*)&netdev_netmask, netmask_string, INET_ADDRSTRLEN))) { PERROR("inet_ntop"); } netdev_prefix = nm_utils_ip4_netmask_to_prefix (netdev_netmask); }
CInputPlayback* CInputPlayback::Create(CPacketFilterGraph *graph, IEngine *engine) { CInputPlayback *result = new CInputPlayback(graph); if (AM_UNLIKELY(result && (ME_OK != result->Construct(engine)))) { delete result; result = NULL; } return result; }
/* * CSimplePacketPool */ CSimplePacketPool* CSimplePacketPool::Create(const char *pName, AM_UINT count, AM_UINT objectSize) { CSimplePacketPool* result = new CSimplePacketPool(pName); if (AM_UNLIKELY(result && result->Construct(count, objectSize) != ME_OK)) { delete result; result = NULL; } return result; }
/* * CFixedPacketPool */ CFixedPacketPool* CFixedPacketPool::Create(const char *pName, AM_UINT count, AM_UINT dataSize) { CFixedPacketPool* result = new CFixedPacketPool(pName); if (AM_UNLIKELY(result && result->Construct(count, dataSize) != ME_OK)) { delete result; result = NULL; } return result; }
void NetInfoIPv4::set_prefix(uint32_t prefix) { netdev_prefix = prefix; netdev_netmask = htonl(((uint32_t) -1) << (sizeof(uint32_t) * 8 - netdev_prefix)); memset(netmask_string, 0, sizeof(netmask_string)); if (AM_UNLIKELY(NULL == inet_ntop(AF_INET, (void*)&netdev_netmask, netmask_string, INET_ADDRSTRLEN))) { PERROR("inet_ntop"); } }
bool AmPrivacyMaskDPTZ::unmap_pm(void) { if (mIsPrivacyMaskMapped) { if (AM_UNLIKELY(ioctl(mIav, IAV_IOC_UNMAP_PRIVACY_MASK_EX) < 0)) { PERROR("IAV_IOC_UNMAP_PRIVACY_MASK_EX"); } else { mIsPrivacyMaskMapped = false; } } return !mIsPrivacyMaskMapped; }
void NetDeviceInfo::add_netdev_ipv6(NetInfoIPv6 *ip6) { NetInfoIPv6 **info = &ipv6; for (; *info; info = &((*info)->info_next)) { if (AM_UNLIKELY(*(*info) == *ip6)) { if (AM_LIKELY(*info != ip6)) { delete ip6; } return; } } *info = ip6; }
CRtpSessionVideo* CRtpSessionVideo::Create(AM_UINT streamid, AM_UINT oldstreamid, CRtspServer *server, AM_VIDEO_INFO *videoInfo) { CRtpSessionVideo* result = new CRtpSessionVideo(streamid, oldstreamid); if (AM_UNLIKELY(result && (ME_OK != result->Construct(server, videoInfo)))) { delete result; result = NULL; } return result; }
CRtspServer* CRtspServer::Create(CRtspFilter *filter, bool RTPriority, int priority) { CRtspServer* result = new CRtspServer(filter, RTPriority, priority); if (AM_UNLIKELY(result && (ME_OK != result->Construct()))) { delete result; result = NULL; } return result; }
AM_ERR CSimplePacketPool::Construct(AM_UINT count, AM_UINT objectSize) { AM_ERR err = ME_ERROR; if (AM_UNLIKELY((count > 0) && (err = inherited::Construct(count)) != ME_OK)) { return err; } AM_ASSERT(objectSize == sizeof(CPacket)); mpPacketMemory = new CPacket[count]; if (AM_UNLIKELY(mpPacketMemory == NULL)) { return ME_NO_MEMORY; } else { for (AM_UINT i = 0; i < count; ++ i) { CPacket *pPacket = &mpPacketMemory[i]; AM_ENSURE_OK_( mpBufferQ->PostMsg(&pPacket, sizeof(pPacket))); } } return ME_OK; }
static inline void init() { AM_LOCK(); if (AM_UNLIKELY(!AO_load_acquire_read(&isInitialized))) { if (0 == isInitialized) { get_log_level(); get_log_target(); get_timestamp_setting(); AO_store_release_write(&isInitialized, 1); } } AM_UNLOCK(); }
void NetInfoIPv6::add_dns(DnsIPv6 *dnsInfo) { DnsIPv6 **info = &dns; for (; *info; info = &((*info)->dns_next)) { if (AM_UNLIKELY((*(*info)) == (*dnsInfo))) { if (AM_LIKELY(*info != dnsInfo)) { delete dnsInfo; } return; } } *info = dnsInfo; }
AM_ERR CMp4Builder::UpdateVideoIdx(AM_INT deltaPts, AM_UINT sampleSize, AM_UINT chunk_offset, AM_U8 sync_point) { //AM_U16 start_code[2]; //start_code[0] = 0x1; _v_stsz[mVideoCnt] = LeToBe32(sampleSize); //sample size _v_stco[mVideoCnt] = LeToBe32(chunk_offset); //chunk_offset AM_INT ctts = 0; if (AM_UNLIKELY(mVideoCnt == 0)) { ctts = 0; } else { ctts = _last_ctts + (deltaPts - mH264Info.rate); // delta to dts if (AM_UNLIKELY(ctts < 0)) { for (AM_INT i = mVideoCnt - 1; i >= 0; i--) { // adjust all previous ctts _ctts[2*i + 1] = LeToBe32((BeToLe32(_ctts[2*i + 1]) - ctts)); } ctts = 0; mVideoDuration += ctts; } } //DEBUG("delta PTS %d, ctts %d -> %d, mVideoDuration %d\n", // deltaPts, _last_ctts, ctts, mVideoDuration); _ctts[2*mVideoCnt] = LeToBe32(1); // sample_count = 1 _ctts[2*mVideoCnt + 1] = LeToBe32(ctts); _last_ctts = ctts; mVideoCnt++; mVideoDuration += deltaPts; if (sync_point) { _stss[mStssCnt] = LeToBe32(mVideoCnt); mStssCnt++; } // DEBUG("mVideoDuration %d, cnt %d\n", mVideoDuration, mVideoCnt); return ME_OK; }