Files
2026-08-24 10:03:24 +08:00

137 lines
3.5 KiB
C

/*
* Copyright (C) 2017 Amlogic Corporation.
*
* 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.
*/
#define LOG_TAG "audio_hw_input_dtv"
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include "aml_audio_log.h"
#include "dtv_private_object.h"
#include "device_patch_mgr.h"
#ifdef USE_DTV
#include "dmx_audio_es.h"
#endif
int get_dtv_aformat(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
return dtv_obj->dtv_aformat;
}
void set_dtv_aformat(struct aml_audio_device *adev, int format)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
dtv_obj->dtv_aformat = format;
}
int get_dtv_sound_mode(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
return dtv_obj->dtv_sound_mode;
}
void set_dtv_sound_mode(struct aml_audio_device *adev, int sound_mode)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
dtv_obj->dtv_sound_mode = sound_mode;
}
float get_dtv_volume(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
return dtv_obj->dtv_volume;
}
void set_dtv_volume(struct aml_audio_device *adev, float volume)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
dtv_obj->dtv_volume = volume;
}
void enable_dtv_multi_demux(struct aml_audio_device *adev, int enable)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
dtv_obj->is_multi_demux = enable;
}
bool is_dtv_multi_demux(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
return dtv_obj->is_multi_demux;
}
void acquire_dtv_mutex_lock(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
pthread_mutex_lock(&dtv_obj->dtv_lock);
}
void release_dtv_mutex_lock(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
pthread_mutex_unlock(&dtv_obj->dtv_lock);
}
static bool is_multi_demux()
{
if (access("/sys/module/dvb_demux/",F_OK) == 0 ||
access("/sys/module/amlogic_dvb_demux/",F_OK) == 0) {
ALOGI("use AmHwMultiDemux mode\n");
return true;
}
ALOGI("use AmHwDemux mode\n");
return false;
}
int init_dtv_object(struct aml_audio_device *adev)
{
int ret = 0;
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
if (!dtv_obj) {
ALOGE("%s() Error, dtv_obj = NULL, return!", __func__);
return -EINVAL;
}
enable_dtv_multi_demux(adev, is_multi_demux());
pthread_mutex_init(&dtv_obj->dtv_lock, NULL);
dtv_obj->dtv_sound_mode = 0;
dtv_obj->dtv_volume = 1.0;
return ret;
}
int destroy_dtv_object(struct aml_audio_device *adev)
{
struct dtv_private_object *dtv_obj = get_dtv_object(adev);
if (!dtv_obj) {
ALOGW("%s() Warning, dtv_obj = NULL!", __func__);
return -EINVAL;
}
pthread_mutex_destroy(&dtv_obj->dtv_lock);
//free dtv_obj
aml_audio_free(dtv_obj);
return 0;
}