author | Xiaoliang Wang <xiaoliang.wang@amlogic.com> | 2016-05-04 10:19:13 (GMT) |
---|---|---|
committer | Xiaoliang Wang <xiaoliang.wang@amlogic.com> | 2016-05-04 10:54:30 (GMT) |
commit | 8ace210c5c92daf59f31240813812fea47594a6c (patch) | |
tree | dd6b840c553a1c48f1c1e582dc245e8d24a2efa0 | |
parent | 88780c448b0f7b7f58aae6d54a7b5aa32c8d2a06 (diff) | |
download | SubTitle-8ace210c5c92daf59f31240813812fea47594a6c.zip SubTitle-8ace210c5c92daf59f31240813812fea47594a6c.tar.gz SubTitle-8ace210c5c92daf59f31240813812fea47594a6c.tar.bz2 |
sync code with android 5.1
Change-Id: I6e442fd4eeb26be2c5847c421715236a7ce9b815
-rw-r--r-- | jni/subtitle/sub_dvb_sub.c | 10 | ||||
-rw-r--r-- | jni/subtitle/sub_dvb_sub.h | 10 | ||||
-rw-r--r-- | jni/subtitle/sub_jni.c | 8 | ||||
-rw-r--r-- | jni/subtitle/sub_subtitle.c | 80 | ||||
-rw-r--r-- | jni/subtitle/sub_subtitle.h | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | res/layout/subtitleview.xml | 22 | ||||
-rw-r--r-- | service/Android.mk | 16 | ||||
-rw-r--r-- | service/ISubTitleService.cpp | 547 | ||||
-rw-r--r-- | service/ISubTitleService.h | 72 | ||||
-rw-r--r-- | src/com/droidlogic/SubTitleService/ISubTitleService.aidl | 4 | ||||
-rw-r--r-- | src/com/droidlogic/SubTitleService/SubTitleService.java | 181 | ||||
-rw-r--r-- | src/com/subtitleparser/SubData.java | 104 | ||||
-rw-r--r-- | src/com/subtitleparser/SubtitleFile.java | 22 | ||||
-rw-r--r-- | src/com/subtitleparser/SubtitleUtils.java | 10 | ||||
-rw-r--r--[-rwxr-xr-x] | src/com/subtitleparser/subtypes/InSubParser.java | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | src/com/subtitleparser/subtypes/RawData.java | 6 | ||||
-rw-r--r-- | src/com/subtitleview/SubtitleView.java | 26 |
17 files changed, 996 insertions, 128 deletions
diff --git a/jni/subtitle/sub_dvb_sub.c b/jni/subtitle/sub_dvb_sub.c index 8950368..9e27bd4 100644 --- a/jni/subtitle/sub_dvb_sub.c +++ b/jni/subtitle/sub_dvb_sub.c @@ -1378,6 +1378,7 @@ static void save_display_set(DVBSubContext *ctx, AML_SPUVAR *spu) uint32_t *pbuf = NULL; char filename[32]; static int fileno_index = 0; + DVBSubDisplayDefinition *display_def = ctx->display_definition; x_pos = -1; y_pos = -1; width = 0; @@ -1434,6 +1435,10 @@ static void save_display_set(DVBSubContext *ctx, AML_SPUVAR *spu) spu->spu_height = height; spu->spu_start_x = x_pos; spu->spu_start_y = y_pos; + if (display_def && display_def->width !=0 && display_def->height !=0) { + spu->spu_origin_display_w = display_def->width; + spu->spu_origin_display_h = display_def->height; + } for (display = ctx->display_list; display; display = display->next) { @@ -1554,6 +1559,8 @@ static void dvbsub_parse_display_definition_segment(const uint8_t *buf, display_def->y = 0; display_def->width = bytestream_get_be16(&buf) + 1; display_def->height = bytestream_get_be16(&buf) + 1; + LOGI("-[%s],display_def->width=%d,height=%d,info_byte=%d,buf_size=%d--\n",__FUNCTION__, + display_def->width,display_def->height,info_byte,buf_size); if (buf_size < 13) return; if (info_byte & 1 << 3) // display_window_flag @@ -1683,6 +1690,9 @@ int dvbsub_decode(AML_SPUVAR *spu, const uint8_t *psrc, const int size) spu->spu_height = 0; spu->spu_start_x = 0; spu->spu_start_y = 0; + //default spu display in windows width and height + spu->spu_origin_display_w = 720; + spu->spu_origin_display_h = 576; #if 0 LOGI("DVB sub packet:\n"); for (i = 0; i < buf_size; i++) diff --git a/jni/subtitle/sub_dvb_sub.h b/jni/subtitle/sub_dvb_sub.h index eaec308..aa0591b 100644 --- a/jni/subtitle/sub_dvb_sub.h +++ b/jni/subtitle/sub_dvb_sub.h @@ -48,6 +48,14 @@ #endif #endif +#ifndef av_unused +#if defined(__GNUC__) +# define av_unused __attribute__((unused)) +#else +# define av_unused +#endif +#endif + #ifndef AV_RB16 #define AV_RB16(x) \ ((((const uint8_t*)(x))[0] << 8) | \ @@ -530,7 +538,7 @@ static inline uint32_t bytestream_get_be16(const uint8_t **ptr) { uint32_t tmp; tmp = (*ptr)[1] | ((*ptr)[0] << 8); - *ptr += 3; + *ptr += 2; return tmp; } diff --git a/jni/subtitle/sub_jni.c b/jni/subtitle/sub_jni.c index 6de90ab..1fbf489 100644 --- a/jni/subtitle/sub_jni.c +++ b/jni/subtitle/sub_jni.c @@ -251,7 +251,7 @@ JNIEXPORT jobject JNICALL getrawdata(JNIEnv *env, jclass cl, jint msec) return NULL; } jmethodID constrforpgs = (*env)->GetMethodID(env, cls, "<init>", - "([IIIIIIILjava/lang/String;)V"); + "([IIIIIIIIILjava/lang/String;)V"); if (!constrforpgs) { LOGE("com/subtitleparser/subtypes/RawData: failed to get constructor method's ID"); @@ -360,9 +360,10 @@ JNIEXPORT jobject JNICALL getrawdata(JNIEnv *env, jclass cl, jint msec) jobject obj = (*env)->NewObject(env, cls, constrforpgs, array, 1, get_inter_spu_width(), - get_inter_spu_height(), sub_size, + get_inter_spu_height(), 0, 0, sub_size, sub_start_pts, delay_pts, 0); LOGE("getrawdata: NewObject finish"); + free_last_inter_spu_data(); add_read_position(); if (!obj) { @@ -392,8 +393,9 @@ JNIEXPORT jobject JNICALL getrawdata(JNIEnv *env, jclass cl, jint msec) jobject obj = (*env)->NewObject(env, cls, constrforpgs, array, 1, get_inter_spu_width(), - get_inter_spu_height(), sub_size, + get_inter_spu_height(), get_inter_spu_origin_width(), get_inter_spu_origin_height(), sub_size, start_time, delay_time, 0); + free_last_inter_spu_data(); add_read_position(); if (!obj) { diff --git a/jni/subtitle/sub_subtitle.c b/jni/subtitle/sub_subtitle.c index d91d92d..3cfc30e 100644 --- a/jni/subtitle/sub_subtitle.c +++ b/jni/subtitle/sub_subtitle.c @@ -111,6 +111,10 @@ typedef struct unsigned rgba_pattern2; unsigned rgba_pattern3; char *data; + unsigned int spu_origin_display_w; //for bitmap subtitle + unsigned int spu_origin_display_h; + unsigned short spu_start_x; + unsigned short spu_start_y; } subtitle_data_t; static subtitle_data_t inter_subtitle_data[MAX_SUBTITLE_PACKET_WRITE]; @@ -435,7 +439,7 @@ int get_spu(AML_SPUVAR *spu, int read_sub_fd) || (spu_buf_piece[rd_oft++] != 0x4d) || (spu_buf_piece[rd_oft++] != 0x4c) || (spu_buf_piece[rd_oft++] != 0x55) - || (spu_buf_piece[rd_oft++] != 0xaa)) + || ((spu_buf_piece[rd_oft++] & 0xfe) != 0xaa)) { LOGI("\n wrong subtitle header :%x %x %x %x %x %x %x %x %x %x %x %x \n", spu_buf_piece[0], spu_buf_piece[1], spu_buf_piece[2], spu_buf_piece[3], spu_buf_piece[4], spu_buf_piece[5], spu_buf_piece[6], spu_buf_piece[7], spu_buf_piece[8], spu_buf_piece[9], spu_buf_piece[10], spu_buf_piece[11]); ret = @@ -507,7 +511,8 @@ int get_spu(AML_SPUVAR *spu, int read_sub_fd) duration_pts |= spu_buf_piece[rd_oft++] << 16; duration_pts |= spu_buf_piece[rd_oft++] << 8; duration_pts |= spu_buf_piece[rd_oft++]; - LOGI("duration_pts is %d, current_length=%d ,rd_oft is %d\n", duration_pts, current_length, rd_oft); + int has_alpha = spu_buf_piece[4] & 0x01; + LOGI("duration_pts is %d, current_length=%d ,rd_oft is %d, has_alpha=%d\n", duration_pts, current_length, rd_oft, has_alpha); avihandle = (DivXSubPictHdr *)(spu_buf_piece + rd_oft); spu->spu_data = malloc(VOB_SUB_SIZE); memset(spu->spu_data, 0, VOB_SUB_SIZE); @@ -548,11 +553,15 @@ int get_spu(AML_SPUVAR *spu, int read_sub_fd) LOGI(" spu->rgba_background == 0x%x, spu->rgba_pattern1 == 0x%x\n", spu->rgba_background, spu->rgba_pattern1); LOGI(" spu->rgba_pattern2 == 0x%x, spu->rgba_pattern3 == 0x%x\n", spu->rgba_pattern2, spu->rgba_pattern3); ptrPXDRead = (unsigned short *) & (avihandle->rleData); + //if has alpha, header had another 4 bytes + if (has_alpha) + ptrPXDRead += 2; + FillPixel(ptrPXDRead, spu->spu_data, 1, spu, avihandle->field_offset); - ptrPXDRead = - (unsigned long *)((unsigned long)(&avihandle->rleData) + - (unsigned long)(avihandle->field_offset)); + //ptrPXDRead = + // (unsigned long *)((unsigned long)(&avihandle->rleData) + + // (unsigned long)(avihandle->field_offset)); FillPixel(ptrPXDRead, spu->spu_data + VOB_SUB_SIZE / 2, 2, spu, avihandle->field_offset); ret = 0; @@ -860,19 +869,26 @@ int write_subtitle_file(AML_SPUVAR *spu) inter_subtitle_data[file_position].resize_width = spu->spu_width; inter_subtitle_data[file_position].resize_height = spu->spu_height; inter_subtitle_data[file_position].rgba_enable = spu->rgba_enable; - inter_subtitle_data[file_position].rgba_background = - spu->rgba_background; + inter_subtitle_data[file_position].rgba_background = spu->rgba_background; inter_subtitle_data[file_position].rgba_pattern1 = spu->rgba_pattern1; inter_subtitle_data[file_position].rgba_pattern2 = spu->rgba_pattern2; inter_subtitle_data[file_position].rgba_pattern3 = spu->rgba_pattern3; - LOGI(" write_subtitle_file[%d], sublen=%d, subtitle_type is 0x%x size: %d subtitle_pts =%u,subtitle_delay_pts=%u \n", file_position, sublen, inter_subtitle_data[read_position].subtitle_type, inter_subtitle_data[file_position].data_size, inter_subtitle_data[file_position].subtitle_pts, inter_subtitle_data[file_position].subtitle_delay_pts); + LOGI(" write_subtitle_file[%d], sublen=%d, subtitle_type is 0x%x size: %d subtitle_pts =%u,subtitle_delay_pts=%u \n",file_position,sublen,inter_subtitle_data[read_position].subtitle_type, + inter_subtitle_data[file_position].data_size,inter_subtitle_data[file_position].subtitle_pts,inter_subtitle_data[file_position].subtitle_delay_pts); if (spu->subtitle_type == SUBTITLE_PGS) { inter_subtitle_type = SUBTITLE_PGS; file_position = ADD_SUBTITLE_POSITION(file_position); } - else if (spu->subtitle_type == SUBTITLE_DVB) - { + else if(spu->subtitle_type == SUBTITLE_DVB){ + inter_subtitle_data[file_position].spu_origin_display_w = spu->spu_origin_display_w; + inter_subtitle_data[file_position].spu_origin_display_h = spu->spu_origin_display_h; + inter_subtitle_data[file_position].spu_start_x = spu->spu_start_x; + inter_subtitle_data[file_position].spu_start_y = spu->spu_start_y; + + LOGI("spu_origin_display[%d,%d],start[%d,%d]-\n",inter_subtitle_data[file_position].spu_origin_display_w, + inter_subtitle_data[file_position].spu_origin_display_h,inter_subtitle_data[file_position].spu_start_x, + inter_subtitle_data[file_position].spu_start_y); inter_subtitle_type = SUBTITLE_DVB; file_position = ADD_SUBTITLE_POSITION(file_position); } @@ -890,7 +906,7 @@ int write_subtitle_file(AML_SPUVAR *spu) int read_subtitle_file() { - LOGI("subtitle data address is %x\n\n", inter_subtitle_data[file_position].data); + LOGI("subtitle data address is %p\n", inter_subtitle_data[file_position].data); return 0; } @@ -1046,6 +1062,26 @@ void free_inter_spu_data() return; } +void free_last_inter_spu_data() +{ + int tmp_pos = 0; + if (read_position > 0) + { + tmp_pos = read_position - 1; + } + else + { + tmp_pos = sublen - 1; + } + + if (inter_subtitle_data[tmp_pos].data) + { + free(inter_subtitle_data[tmp_pos].data); + inter_subtitle_data[tmp_pos].data = NULL; + } + return; +} + char *get_inter_spu_data() { return inter_subtitle_data[read_position].data; @@ -1063,6 +1099,26 @@ int get_inter_spu_height() //return inter_subtitle_data[read_position].subtitle_height; } +int get_inter_spu_origin_width() +{ + return inter_subtitle_data[read_position].spu_origin_display_w; +} + +int get_inter_spu_origin_height() +{ + return inter_subtitle_data[read_position].spu_origin_display_h; +} + +int get_inter_start_x() +{ + return inter_subtitle_data[read_position].spu_start_x; +} + +int get_inter_start_y() +{ + return inter_subtitle_data[read_position].spu_start_y; +} + unsigned get_inter_spu_pts() { return inter_subtitle_data[read_position].subtitle_pts; @@ -1398,7 +1454,7 @@ int close_subtitle() } restlen = 0; int i = 0; - for (i = 0; i < MAX_SUBTITLE_PACKET_WRITE; i++) + for (i = 0; i < sublen; i++) { if (inter_subtitle_data[i].data) free(inter_subtitle_data[i].data); diff --git a/jni/subtitle/sub_subtitle.h b/jni/subtitle/sub_subtitle.h index 438bcc9..f003568 100644 --- a/jni/subtitle/sub_subtitle.h +++ b/jni/subtitle/sub_subtitle.h @@ -48,6 +48,8 @@ typedef struct unsigned short top_pxd_addr; unsigned short bottom_pxd_addr; + unsigned int spu_origin_display_w; //for bitmap subtitle + unsigned int spu_origin_display_h; unsigned disp_colcon_addr; unsigned char display_pending; unsigned char displaying; diff --git a/res/layout/subtitleview.xml b/res/layout/subtitleview.xml index ad83dc8..6ed086c 100755..100644 --- a/res/layout/subtitleview.xml +++ b/res/layout/subtitleview.xml @@ -1,17 +1,15 @@ <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/sub"
+ android:id="@+id/sub"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
-
- <com.subtitleview.SubtitleView
- android:id="@+id/subtitle"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="50dp"
- >
- </com.subtitleview.SubtitleView>
-
+
+ <com.subtitleview.SubtitleView
+ android:id="@+id/subtitle"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_centerHorizontal="true"
+ android:layout_alignParentBottom="true"
+ android:layout_marginBottom="50dp">
+ </com.subtitleview.SubtitleView>
</RelativeLayout>
\ No newline at end of file diff --git a/service/Android.mk b/service/Android.mk new file mode 100644 index 0000000..3dfc87d --- a/dev/null +++ b/service/Android.mk @@ -0,0 +1,16 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + ISubTitleService.cpp + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libcutils \ + libbinder + +LOCAL_MODULE:= libsubtitleservice + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file diff --git a/service/ISubTitleService.cpp b/service/ISubTitleService.cpp new file mode 100644 index 0000000..278e546 --- a/dev/null +++ b/service/ISubTitleService.cpp @@ -0,0 +1,547 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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. + * @author xiaoliang.wang + * @version 1.0 + * @date 2015/07/07 + * @par function description: + * - 1 invoke subtile service from native to java + */ + +#define LOG_TAG "ISubTitleService" +//#define LOG_NDEBUG 0 + +#include <utils/Log.h> +#include <stdint.h> +#include <sys/types.h> +#include <binder/Parcel.h> +#include <ISubTitleService.h> + +namespace android { + +// must be kept in sync with ISubTitleService.aidl +enum { + SUB_OPEN = IBinder::FIRST_CALL_TRANSACTION, + SUB_OPEN_IDX = IBinder::FIRST_CALL_TRANSACTION + 1, + SUB_CLOSE = IBinder::FIRST_CALL_TRANSACTION + 2, + SUB_GET_TOTAL = IBinder::FIRST_CALL_TRANSACTION + 3, + SUB_GET_INNER_TOTAL = IBinder::FIRST_CALL_TRANSACTION + 4, + SUB_GET_EXTERNAL_TOTAL = IBinder::FIRST_CALL_TRANSACTION + 5, + SUB_NEXT = IBinder::FIRST_CALL_TRANSACTION + 6, + SUB_PREVIOUS = IBinder::FIRST_CALL_TRANSACTION + 7, + SUB_SHOW_SUB = IBinder::FIRST_CALL_TRANSACTION + 8, + SUB_OPTION = IBinder::FIRST_CALL_TRANSACTION + 9, + SUB_GET_TYPE = IBinder::FIRST_CALL_TRANSACTION + 10, + SUB_GET_TYPE_STR = IBinder::FIRST_CALL_TRANSACTION + 11, + SUB_GET_TYPE_DETIAL = IBinder::FIRST_CALL_TRANSACTION + 12, + SUB_SET_TEXT_COLOR = IBinder::FIRST_CALL_TRANSACTION + 13, + SUB_SET_TEXT_SIZE = IBinder::FIRST_CALL_TRANSACTION + 14, + SUB_SET_GRAVITY = IBinder::FIRST_CALL_TRANSACTION + 15, + SUB_SET_TEXT_STYLE = IBinder::FIRST_CALL_TRANSACTION + 16, + SUB_SET_POS_HEIGHT = IBinder::FIRST_CALL_TRANSACTION + 17, + SUB_SET_IMG_RATIO = IBinder::FIRST_CALL_TRANSACTION + 18, + SUB_CLEAR = IBinder::FIRST_CALL_TRANSACTION + 19, + SUB_RESET_FOR_SEEK = IBinder::FIRST_CALL_TRANSACTION + 20, + SUB_HIDE = IBinder::FIRST_CALL_TRANSACTION + 21, + SUB_DISPLAY = IBinder::FIRST_CALL_TRANSACTION + 22, + SUB_GET_CUR_NAME = IBinder::FIRST_CALL_TRANSACTION + 23, + SUB_GET_NAME = IBinder::FIRST_CALL_TRANSACTION + 24, + SUB_GET_LANGUAGE = IBinder::FIRST_CALL_TRANSACTION + 25, + SUB_LOAD = IBinder::FIRST_CALL_TRANSACTION + 26, + SUB_SET_SURFACE_PARAM = IBinder::FIRST_CALL_TRANSACTION + 27, +}; + +class BpSubTitleService : public BpInterface<ISubTitleService> +{ +public: + BpSubTitleService(const sp<IBinder>& impl) + : BpInterface<ISubTitleService>(impl) + { + } + + virtual void open(const String16& path) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeString16(path); + ALOGV("open path:%s\n", String8(path).string()); + + if (remote()->transact(SUB_OPEN, data, &reply) != NO_ERROR) { + ALOGD("open not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("open caught exception %d\n", err); + } + return; + } + + virtual void openIdx(int32_t idx) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(idx); + ALOGV("openIdx idx:%d\n", idx); + + if (remote()->transact(SUB_OPEN_IDX, data, &reply) != NO_ERROR) { + ALOGD("openIdx could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("openIdx caught exception %d\n", err); + } + return; + } + + virtual void close() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("close\n"); + + if (remote()->transact(SUB_CLOSE, data, &reply) != NO_ERROR) { + ALOGD("close could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("close caught exception %d\n", err); + } + return; + } + + virtual int32_t getTotal() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("getTotal\n"); + + if (remote()->transact(SUB_GET_TOTAL, data, &reply) != NO_ERROR) { + ALOGD("getTotal could not contact remote\n"); + return -1; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getTotal caught exception %d\n", err); + return -1; + } + return reply.readInt32(); + } + + virtual void next() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("next\n"); + + if (remote()->transact(SUB_NEXT, data, &reply) != NO_ERROR) { + ALOGD("next could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("next caught exception %d\n", err); + } + return; + } + + virtual void previous() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("previous\n"); + + if (remote()->transact(SUB_PREVIOUS, data, &reply) != NO_ERROR) { + ALOGD("previous could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("previous caught exception %d\n", err); + } + return; + } + + virtual void showSub(int32_t pos) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(pos); + ALOGV("showSub pos:%d\n", pos); + + if (remote()->transact(SUB_SHOW_SUB, data, &reply) != NO_ERROR) { + ALOGD("showSub could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("showSub caught exception %d\n", err); + } + return; + } + + virtual void option() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("option\n"); + + if (remote()->transact(SUB_OPTION, data, &reply) != NO_ERROR) { + ALOGD("option could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("option caught exception %d\n", err); + } + return; + } + + virtual int32_t getType() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("getType\n"); + + if (remote()->transact(SUB_GET_TYPE, data, &reply) != NO_ERROR) { + ALOGD("getType could not contact remote\n"); + return 0; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getType caught exception %d\n", err); + return 0; + } + return reply.readInt32(); + } + + virtual const String16& getTypeStr() const + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("getTypeStr\n"); + + if (remote()->transact(SUB_GET_TYPE_STR, data, &reply) != NO_ERROR) { + ALOGD("getTypeStr could not contact remote\n"); + return String16(""); + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getTypeStr caught exception %d\n", err); + return String16(""); + } + return reply.readString16(); + } + + virtual int32_t getTypeDetial() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("getTypeDetial\n"); + + if (remote()->transact(SUB_GET_TYPE_DETIAL, data, &reply) != NO_ERROR) { + ALOGD("getTypeDetial could not contact remote\n"); + return 0; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getTypeDetial caught exception %d\n", err); + return 0; + } + return reply.readInt32(); + } + + virtual void setTextColor(int32_t color) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(color); + ALOGV("setTextColor color:%d\n", color); + + if (remote()->transact(SUB_SET_TEXT_COLOR, data, &reply) != NO_ERROR) { + ALOGD("setTextColor could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setTextColor caught exception %d\n", err); + } + return; + } + + virtual void setTextSize(int32_t size) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(size); + ALOGV("setTextSize size:%d\n", size); + + if (remote()->transact(SUB_SET_TEXT_SIZE, data, &reply) != NO_ERROR) { + ALOGD("setTextSize could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setTextSize caught exception %d\n", err); + } + return; + } + + virtual void setGravity(int32_t gravity) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(gravity); + ALOGV("setGravity gravity:%d\n", gravity); + + if (remote()->transact(SUB_SET_GRAVITY, data, &reply) != NO_ERROR) { + ALOGD("setGravity could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setGravity caught exception %d\n", err); + } + return; + } + + virtual void setTextStyle(int32_t style) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(style); + ALOGV("setTextStyle style:%d\n", style); + + if (remote()->transact(SUB_SET_TEXT_STYLE, data, &reply) != NO_ERROR) { + ALOGD("setTextStyle could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setTextStyle caught exception %d\n", err); + } + return; + } + + virtual void setPosHeight(int32_t height) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(height); + ALOGV("setPosHeight height:%d\n", height); + + if (remote()->transact(SUB_SET_POS_HEIGHT, data, &reply) != NO_ERROR) { + ALOGD("setPosHeight could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setPosHeight caught exception %d\n", err); + } + return; + } + + virtual void setImgRatio(float ratioW, float ratioH, int32_t maxW, int32_t maxH) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeFloat(ratioW); + data.writeFloat(ratioH); + data.writeInt32(maxW); + data.writeInt32(maxH); + ALOGV("setImgRatio (ratioW, ratioH, maxW, maxH):(%f, %f, d%, %d)\n", ratioW, ratioH, maxW, maxH); + + if (remote()->transact(SUB_SET_IMG_RATIO, data, &reply) != NO_ERROR) { + ALOGD("setImgRatio could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setImgRatio caught exception %d\n", err); + } + return; + } + + virtual void clear() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("clear\n"); + + if (remote()->transact(SUB_CLEAR, data, &reply) != NO_ERROR) { + ALOGD("clear could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("clear caught exception %d\n", err); + } + return; + } + + virtual void resetForSeek() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("resetForSeek\n"); + + if (remote()->transact(SUB_RESET_FOR_SEEK, data, &reply) != NO_ERROR) { + ALOGD("resetForSeek could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("resetForSeek caught exception %d\n", err); + } + return; + } + + virtual void hide() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("hide\n"); + + if (remote()->transact(SUB_HIDE, data, &reply) != NO_ERROR) { + ALOGD("hide could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("hide caught exception %d\n", err); + } + return; + } + + virtual void display() + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("display\n"); + + if (remote()->transact(SUB_DISPLAY, data, &reply) != NO_ERROR) { + ALOGD("display could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("display caught exception %d\n", err); + } + return; + } + + virtual const String16& getCurName() const + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + ALOGV("getCurName\n"); + + if (remote()->transact(SUB_GET_CUR_NAME, data, &reply) != NO_ERROR) { + ALOGD("getCurName could not contact remote\n"); + return String16(""); + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getCurName caught exception %d\n", err); + return String16(""); + } + return reply.readString16(); + } + + virtual const String16& getName(int32_t idx) const + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(idx); + ALOGV("getName idx:%d\n", idx); + + if (remote()->transact(SUB_GET_NAME, data, &reply) != NO_ERROR) { + ALOGD("getName could not contact remote\n"); + return String16(""); + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getName caught exception %d\n", err); + return String16(""); + } + return reply.readString16(); + } + + virtual const String16& getLanguage(int32_t idx) const + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(idx); + ALOGV("getLanguage idx:%d\n", idx); + + if (remote()->transact(SUB_GET_LANGUAGE, data, &reply) != NO_ERROR) { + ALOGD("getLanguage could not contact remote\n"); + return String16(""); + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("getLanguage caught exception %d\n", err); + return String16(""); + } + return reply.readString16(); + } + + virtual bool load(const String16& path) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeString16(path); + ALOGV("load path:%s\n", String8(path).string()); + + if (remote()->transact(SUB_LOAD, data, &reply) != NO_ERROR) { + ALOGD("load could not contact remote\n"); + return false; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("load caught exception %d\n", err); + return false; + } + return reply.readInt32() != 0; + } + + virtual void setSurfaceViewParam(int32_t x, int32_t y, int32_t w, int32_t h) + { + Parcel data, reply; + data.writeInterfaceToken(ISubTitleService::getInterfaceDescriptor()); + data.writeInt32(x); + data.writeInt32(y); + data.writeInt32(w); + data.writeInt32(h); + ALOGV("setSurfaceViewParam (x, y, w, h):(%d, %d, d%, %d)\n", x, y, w, h); + + if (remote()->transact(SUB_SET_SURFACE_PARAM, data, &reply) != NO_ERROR) { + ALOGD("setSurfaceViewParam could not contact remote\n"); + return; + } + int32_t err = reply.readExceptionCode(); + if (err < 0) { + ALOGD("setSurfaceViewParam caught exception %d\n", err); + } + return; + } +}; + +IMPLEMENT_META_INTERFACE(SubTitleService, "com.droidlogic.SubTitleService.ISubTitleService"); + +// ---------------------------------------------------------------------------- + +}; // namespace android diff --git a/service/ISubTitleService.h b/service/ISubTitleService.h new file mode 100644 index 0000000..21cd480 --- a/dev/null +++ b/service/ISubTitleService.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * 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. + * @author xiaoliang.wang + * @version 1.0 + * @date 2015/07/07 + * @par function description: + * - 1 invoke subtile service from native to java + */ + +#ifndef ANDROID_ISUBTITLESERVICE_H +#define ANDROID_ISUBTITLESERVICE_H + +#include <utils/Errors.h> +#include <binder/IInterface.h> +#include <utils/String8.h> +#include <utils/String16.h> + +namespace android { + +// ---------------------------------------------------------------------------- + +// must be kept in sync with interface defined in ISubTitleService.aidl +class ISubTitleService : public IInterface +{ +public: + DECLARE_META_INTERFACE(SubTitleService); + + virtual void open(const String16& path) = 0; + virtual void openIdx(int32_t idx) = 0; + virtual void close() = 0; + virtual int32_t getTotal() = 0; + virtual void next() = 0; + virtual void previous() = 0; + virtual void showSub(int32_t pos) = 0; + virtual void option() = 0; + virtual int32_t getType() = 0; + virtual const String16& getTypeStr() const = 0; + virtual int32_t getTypeDetial() = 0; + virtual void setTextColor(int32_t color) = 0; + virtual void setTextSize(int32_t size) = 0; + virtual void setGravity(int32_t gravity) = 0; + virtual void setTextStyle(int32_t style) = 0; + virtual void setPosHeight(int32_t height) = 0; + virtual void setImgRatio(float ratioW, float ratioH, int32_t maxW, int32_t maxH) = 0; + virtual void clear() = 0; + virtual void resetForSeek() = 0; + virtual void hide() = 0; + virtual void display() = 0; + virtual const String16& getCurName() const = 0; + virtual const String16& getName(int32_t idx) const = 0; + virtual const String16& getLanguage(int32_t idx) const = 0; + virtual bool load(const String16& path) = 0; + virtual void setSurfaceViewParam(int x, int y, int w, int h) = 0; +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_ISUBTITLESERVICE_H
\ No newline at end of file diff --git a/src/com/droidlogic/SubTitleService/ISubTitleService.aidl b/src/com/droidlogic/SubTitleService/ISubTitleService.aidl index 0b38b39..faa626e 100644 --- a/src/com/droidlogic/SubTitleService/ISubTitleService.aidl +++ b/src/com/droidlogic/SubTitleService/ISubTitleService.aidl @@ -6,6 +6,8 @@ interface ISubTitleService void openIdx(int idx); void close(); int getSubTotal(); + int getInnerSubTotal(); + int getExternalSubTotal(); void nextSub(); void preSub(); //void startInSubThread(); @@ -21,7 +23,6 @@ interface ISubTitleService void setTextStyle(int style); void setPosHeight(int height); void setImgSubRatio(float ratioW, float ratioH, int maxW, int maxH); - void setSurfaceViewParam(int x, int y, int w, int h); void clear(); void resetForSeek(); void hide(); @@ -30,4 +31,5 @@ interface ISubTitleService String getSubName(int idx); String getSubLanguage(int idx); boolean load(String path); + void setSurfaceViewParam(int x, int y, int w, int h); }
\ No newline at end of file diff --git a/src/com/droidlogic/SubTitleService/SubTitleService.java b/src/com/droidlogic/SubTitleService/SubTitleService.java index 924d18f..36c87f8 100644 --- a/src/com/droidlogic/SubTitleService/SubTitleService.java +++ b/src/com/droidlogic/SubTitleService/SubTitleService.java @@ -1,6 +1,8 @@ package com.droidlogic.SubTitleService; import android.util.Log; +import android.util.DisplayMetrics; + import android.app.Service; import android.content.BroadcastReceiver; import android.content.Context; @@ -39,9 +41,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.droidlogic.app.SystemControlManager; + public class SubTitleService extends ISubTitleService.Stub { private static final String TAG = "SubTitleService"; private static final String SUBTITLE_WIN_TITLE = "com.droidlogic.subtitle.win"; + private static final String DISPLAY_MODE_SYSFS = "/sys/class/display/mode"; + private SystemControlManager mSystemControl; private static final int OPEN = 0xF0; //random value private static final int SHOW_CONTENT = 0xF1; @@ -74,14 +80,20 @@ public class SubTitleService extends ISubTitleService.Stub { private SubtitleView subTitleView = null; private int mSubTotal = -1; private int mCurSubId = 0; + private int mSetSubId = -1; //for subtitle option private AlertDialog mOptionDialog; private ListView mListView; private int mCurOptSelect = 0; + //for subtitle img ratio + private boolean mRatioSet = false; + //for window scale - private int mOriginTextSize = 20; + private float mRatio = 1.000f; + private int mTextSize = 20; + private int mBottomMargin = 50; //should sync with SubtitleView.xml public SubTitleService(Context context) { LOGI("[SubTitleService]"); @@ -93,38 +105,16 @@ public class SubTitleService extends ISubTitleService.Stub { if (mDebug) Log.i(TAG, msg); } - public void setSurfaceViewParam(int x, int y, int w, int h) { - int originW = mDisplay.getWidth(); - int originH = mDisplay.getHeight(); - if (originW == 0 || originH == 0 || w == 0 || h == 0) { - Log.e(TAG, "[setSurfaceViewParam]originW:" + originW + ", originH:" + originH + ", w:" + w + ", h:" + h); - return; - } - float ratioW = (float)(w / originW); - float ratioH = (float)(h / originH); - - removeView();//view will add in message show content handler - - // update image subtitle size - mWindowLayoutParams.x = x; - mWindowLayoutParams.y = y; - mWindowLayoutParams.width = w; - mWindowLayoutParams.height = h; - LOGI("[setSurfaceViewParam]x:" + mWindowLayoutParams.x + ",y:" + mWindowLayoutParams.y + ",width:" + mWindowLayoutParams.width + ",height:" + mWindowLayoutParams.height); - setImgSubRatio(ratioW, ratioH, w, h); - - // update text subtitle size - setTextSize((int)(mOriginTextSize * ratioW));// take ratioW as ratio for text size - LOGI("[setSurfaceViewParam]ratioW:" + ratioW + ",ratioH:" + ratioH); - } - private void init() { + //get system control + mSystemControl = new SystemControlManager(mContext); + //init view mSubView = LayoutInflater.from(mContext).inflate(R.layout.subtitleview, null); subTitleView = (SubtitleView) mSubView.findViewById(R.id.subtitle); subTitleView.clear(); subTitleView.setTextColor(Color.WHITE); - subTitleView.setTextSize(mOriginTextSize); + subTitleView.setTextSize(20); subTitleView.setTextStyle(Typeface.NORMAL); subTitleView.setViewStatus(true); @@ -167,15 +157,25 @@ public class SubTitleService extends ISubTitleService.Stub { mOptionDialog.dismiss(); } - File file = new File(path); - String name = file.getName(); - if (name == null || (name != null && -1 == name.lastIndexOf('.'))) { - return; + if (path != null && !path.equals("")) { + File file = new File(path); + String name = file.getName(); + if (name == null || (name != null && -1 == name.lastIndexOf('.'))) { + return; + } + mSubtitleUtils = new SubtitleUtils(path); + } + else { + mSubtitleUtils = new SubtitleUtils(); } - mSubtitleUtils = new SubtitleUtils(path); mSubTotal = mSubtitleUtils.getSubTotal(); mCurSubId = mSubtitleUtils.getCurrentInSubtitleIndexByJni(); //get inner subtitle current index as default, 0 is always, if there is no inner subtitle, 0 indicate the first external subtitle + if (mSetSubId >= 0) { + mCurSubId = mSetSubId; + mSetSubId = -1; + } + LOGI("[open] mCurSubId: " + mCurSubId); sendOpenMsg(mCurSubId); //load("http://milleni.ercdn.net/9_test/double_lang_test.xml"); for test @@ -189,6 +189,7 @@ public class SubTitleService extends ISubTitleService.Stub { mSubtitleUtils = null; } mSubTotal = -1; + mSetSubId = -1; sendCloseMsg(); } @@ -197,6 +198,14 @@ public class SubTitleService extends ISubTitleService.Stub { return mSubTotal; } + public int getInnerSubTotal() { + return mSubtitleUtils.getInSubTotal(); + } + + public int getExternalSubTotal() { + return mSubtitleUtils.getExSubTotal(); + } + public void nextSub() { // haven't test LOGI("[nextSub]mCurSubId:" + mCurSubId + ",mSubTotal:" + mSubTotal); if (mSubTotal > 0) { @@ -221,9 +230,11 @@ public class SubTitleService extends ISubTitleService.Stub { public void openIdx(int idx) { LOGI("[openIdx]idx:" + idx); - if (idx > 0 && idx < mSubTotal) { + if (idx >= 0 && idx < mSubTotal) { mCurSubId = idx; sendOpenMsg(idx); + } else { + mSetSubId = idx; } } @@ -251,6 +262,7 @@ public class SubTitleService extends ISubTitleService.Stub { } public void setTextSize (int size) { + mTextSize = size; sendSetTxtSizeMsg(size); } @@ -288,7 +300,7 @@ public class SubTitleService extends ISubTitleService.Stub { public void setImgSubRatio (float ratioW, float ratioH, int maxW, int maxH) { LOGI("[setImgSubRatio] ratioW:" + ratioW + ", ratioH:" + ratioH + ",maxW:" + maxW + ",maxH:" + maxH); - subTitleView.setImgSubRatio(ratioW, ratioH, maxW, maxH); + //subTitleView.setImgSubRatio(ratioW, ratioH, maxW, maxH); } public String getCurName() { @@ -303,7 +315,7 @@ public class SubTitleService extends ISubTitleService.Stub { public String getSubName(int idx) { String name = null; - if (idx > 0 && idx < mSubTotal && mSubtitleUtils != null) { + if (idx >= 0 && idx < mSubTotal && mSubtitleUtils != null) { name = mSubtitleUtils.getSubPath(idx); if (name != null) { int index = name.lastIndexOf("/"); @@ -326,7 +338,7 @@ public class SubTitleService extends ISubTitleService.Stub { String language = null; int index = 0; - if (idx > 0 && idx < mSubTotal && mSubtitleUtils != null) { + if (idx >= 0 && idx < mSubTotal && mSubtitleUtils != null) { language = mSubtitleUtils.getSubPath(idx); if (language != null) { index = language.lastIndexOf("."); @@ -537,6 +549,99 @@ public class SubTitleService extends ISubTitleService.Stub { return ret; } + public void setSurfaceViewParam(int x, int y, int w, int h) { + String mode = mSystemControl.readSysFs(DISPLAY_MODE_SYSFS).replaceAll("\n",""); + int[] curPosition = mSystemControl.getPosition(mode); + int modeW = curPosition[2]; + int modeH = curPosition[3]; + int fbW = mDisplay.getWidth(); + int fbH = mDisplay.getHeight(); + + if (modeW == 0 || modeH == 0 || w == 0 || h == 0) { + return; + } + + removeView();//view will add in message show content handler + + float ratioViewW = ((float)w) / modeW; + float ratioViewH = ((float)h) / modeH; + float ratioFBW = ((float)fbW) /modeW; + float ratioFBH = ((float)fbH) /modeH; + + // update image subtitle size + if (ratioViewW >= ratioViewH) { + mRatio = ratioViewW; + } + else { + mRatio = ratioViewH; + } + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) subTitleView.getLayoutParams(); + layoutParams.bottomMargin=(int)(mBottomMargin * ratioFBH); + subTitleView.setLayoutParams(layoutParams); + mWindowLayoutParams.x = (int)(x * ratioFBW); + mWindowLayoutParams.y = (int)(y * ratioFBH); + mWindowLayoutParams.width = (int)(w * ratioFBW); + mWindowLayoutParams.height = (int)(h * ratioFBH); + LOGI("[setSurfaceViewParam]x:" + mWindowLayoutParams.x + ",y:" + mWindowLayoutParams.y + ",width:" + mWindowLayoutParams.width + ",height:" + mWindowLayoutParams.height); + subTitleView.setImgSubRatio(mRatio); + + // update text subtitle size + setTextSize((int)(mTextSize * mRatio)); + LOGI("[setSurfaceViewParam]mRatio:" + mRatio + ", mTextSize:" + mTextSize); + } + + private void adjustImgRatioDft() { + float ratio = 1.000f; + float ratioMax = 2.000f; + float ratioMin = 0.800f; + + if (mRatioSet) { + return; + } + + int originW = subTitleView.getOriginW(); + int originH = subTitleView.getOriginH(); + LOGI("[adjustImgRatioDft] originW: " + originW + ", originH:" + originH); + if (originW <= 0 || originH <= 0) { + return; + } + + //String mode = mSystemWriteManager.readSysfs(DISPLAY_MODE_SYSFS).replaceAll("\n",""); + //int[] curPosition = mMboxOutputModeManager.getPosition(mode); + //int modeW = curPosition[2]; + //int modeH = curPosition[3]; + //LOGI("[adjustImgRatioDft] modeW: " + modeW + ", modeH:" + modeH); + DisplayMetrics dm = new DisplayMetrics(); + dm = mContext.getResources().getDisplayMetrics(); + int frameW = dm.widthPixels; + int frameH = dm.heightPixels; + LOGI("[adjustImgRatioDft] frameW: " + frameW + ", frameH:" + frameH); + + if (frameW > 0 && frameH > 0) { + float ratioW = ((float)frameW / (float)originW); + float ratioH = ((float)frameH / (float)originH); + LOGI("[adjustImgRatioDft] ratioW: " + ratioW + ", ratioH:" + ratioH); + if (ratioW > ratioH) { + ratio = ratioH; + } + else if (ratioW <= ratioH) { + ratio = ratioW; + } + + if (ratio >= ratioMax) { + ratio = ratioMax; + } + else if (ratio <= ratioMin) { + ratio = ratioMin; + } + } + LOGI("[adjustImgRatioDft] ratio: " + ratio); + if (ratio > 0) { + subTitleView.setImgSubRatio(ratio * mRatio); + } + mRatioSet = true; + } + private String setSublanguage() { String type = null; String able = mContext.getResources().getConfiguration().locale.getCountry(); @@ -594,6 +699,7 @@ public class SubTitleService extends ISubTitleService.Stub { case SHOW_CONTENT: if (subShowState == SUB_ON) { addView(); + adjustImgRatioDft(); subTitleView.tick (msg.arg1); } break; @@ -604,6 +710,7 @@ public class SubTitleService extends ISubTitleService.Stub { subTitleView.stopSubThread(); //close insub parse thread subTitleView.closeSubtitle(); subTitleView.clear(); + mRatioSet = false; } subTitleView.startSubThread(); //open insub parse thread @@ -619,6 +726,7 @@ public class SubTitleService extends ISubTitleService.Stub { subTitleView.closeSubtitle(); subTitleView.clear(); subShowState = SUB_OFF; + mRatioSet = false; } break; @@ -678,6 +786,7 @@ public class SubTitleService extends ISubTitleService.Stub { subTitleView.stopSubThread(); //close insub parse thread subTitleView.closeSubtitle(); subTitleView.clear(); + mRatioSet = false; } try { diff --git a/src/com/subtitleparser/SubData.java b/src/com/subtitleparser/SubData.java index 2b146c0..abd9158 100644 --- a/src/com/subtitleparser/SubData.java +++ b/src/com/subtitleparser/SubData.java @@ -3,49 +3,69 @@ package com.subtitleparser; import android.graphics.Bitmap; public class SubData { - public SubData (String s, int start , int end) { - substr = s; starttime = start; endtime = end; - } - public SubData (Bitmap bit, int start, int end) { - bitmap = bit; starttime = start; endtime = end; - } - public SubData (String s, int start , int end, int size) { - substr = s; starttime = start; endtime = end; subSize = size; - } - public SubData (Bitmap bit, int start, int end, int size) { - bitmap = bit; starttime = start; endtime = end; subSize = size; - } - public int gettype() { - if (bitmap != null) { - return 1; - } - else { - return 0; - } - } - public String getSubString() { - return substr; - } - public Bitmap getSubBitmap() { - return bitmap; - } - public int beginTime() { - return starttime; - } - public void setEndTime (int end) { - endtime = end; - } - public int endTime() { - return endtime; + public SubData (String s, int start , int end) { + substr = s; starttime = start; endtime = end; + } + + public SubData (Bitmap bit, int start, int end) { + bitmap = bit; starttime = start; endtime = end; + } + + public SubData (String s, int start , int end, int size) { + substr = s; starttime = start; endtime = end; subSize = size; + } + + public SubData (Bitmap bit, int start, int end, int size, int o_w, int o_h) { + bitmap = bit; starttime = start; endtime = end; subSize = size; originW=o_w; originH=o_h; + } + + public int gettype() { + if (bitmap != null) { + return 1; } - public int subSize() { - return subSize; + else { + return 0; } + } + + public String getSubString() { + return substr; + } + + public Bitmap getSubBitmap() { + return bitmap; + } + + public int beginTime() { + return starttime; + } + + public void setEndTime (int end) { + endtime = end; + } + + public int endTime() { + return endtime; + } + + public int subSize() { + return subSize; + } + + public int getOriginW() { + return originW; + } + + public int getOriginH() { + return originH; + } - private String substr = null; - private Bitmap bitmap = null; - private int starttime = 0; - private int endtime = 0; - private int subSize = -1; - int type = 0; //0-string,1-bitmap + private String substr = null; + private Bitmap bitmap = null; + private int originW = 0; + private int originH = 0; + private int starttime = 0; + private int endtime = 0; + private int subSize = -1; + int type = 0;//0-string,1-bitmap }
\ No newline at end of file diff --git a/src/com/subtitleparser/SubtitleFile.java b/src/com/subtitleparser/SubtitleFile.java index 79933e9..efbe22c 100644 --- a/src/com/subtitleparser/SubtitleFile.java +++ b/src/com/subtitleparser/SubtitleFile.java @@ -318,16 +318,22 @@ public class SubtitleFile extends LinkedList { text = text.replaceAll ("\\{\\\\fn.*?\\}", ""); text = text.replaceAll ("\\{\\\\r\\}", ""); text = text.replaceAll ("\\{\\\\fs.*?\\}", ""); - if (text.startsWith ("{\\pos(")) { - int idx = text.indexOf (")}m"); - if ( (text.substring (idx + 3)).startsWith (" ")) { - sl = new SubtitleLine (index, startTime, endTime, ""); - } - else { - sl = new SubtitleLine (index, startTime, endTime, text); - } + text = text.replaceAll ("\\{*?\\\\frx.*?\\}", ""); + text = text.replaceAll ("\\{*?\\\\fad.*?\\}", ""); + text = text.replaceAll ("\\{*?\\\\fs.*?\\}", ""); + int idx = text.indexOf (")}m"); + if (idx >= 0 && (text.substring (idx + 3)).startsWith (" ")) { + sl = new SubtitleLine (index, startTime, endTime, ""); } else { + idx = text.indexOf ("0)}"); + if (idx >= 0) { + text = text.substring (idx + 3); + } + idx = text.indexOf ("500)}"); + if (idx >= 0) { + text = text.substring (idx + 5); + } sl = new SubtitleLine (index, startTime, endTime, text); } try { diff --git a/src/com/subtitleparser/SubtitleUtils.java b/src/com/subtitleparser/SubtitleUtils.java index 21945c9..f7a61ac 100644 --- a/src/com/subtitleparser/SubtitleUtils.java +++ b/src/com/subtitleparser/SubtitleUtils.java @@ -59,7 +59,7 @@ public class SubtitleUtils { filename = name; // FileChangedByJni(name); subfile = new File (filename); - if (SystemProperties.getBoolean ("sys.extSubtitle.enable", true) ) { + if (SystemProperties.getBoolean ("sys.extSubtitle.enable", true) && !name.startsWith ("/data/")) { accountExSubtitleNumber(); } } @@ -169,9 +169,9 @@ public class SubtitleUtils { } public SubID getSubID (int index) { - if (subfile == null) { - return null ; - } + //if (subfile == null) { + //return null ; + //} if (index < getInSubTotal() ) { return new SubID ("INSUB", index); } else if (index < getSubTotal() ) { @@ -192,7 +192,7 @@ public class SubtitleUtils { private void accountExSubtitleNumber() { String tmp = subfile.getName(); String prefix = tmp.substring (0, tmp.lastIndexOf ('.') /*+1*/); - Log.i ("SubtitleUtils", "" + prefix); + Log.i ("SubtitleUtils","[accountExSubtitleNumber]prefix:" + prefix); File DirFile = subfile.getParentFile(); int idxindex = 0; boolean skipLrc = false; diff --git a/src/com/subtitleparser/subtypes/InSubParser.java b/src/com/subtitleparser/subtypes/InSubParser.java index fb99db4..ba4eb40 100755..100644 --- a/src/com/subtitleparser/subtypes/InSubParser.java +++ b/src/com/subtitleparser/subtypes/InSubParser.java @@ -83,7 +83,7 @@ class InSubApi extends SubtitleApi { bf_show = Bitmap.createBitmap (inter_data.rawdata, inter_data.width, inter_data.height, Config.ARGB_8888); Log.i ("getdata", "[Bitmap]start time:" + millisec + ",delay time:" + inter_data.sub_delay); - return new SubData (bf_show, inter_data.sub_start, inter_data.sub_delay, inter_data.sub_size); + return new SubData (bf_show, inter_data.sub_start, inter_data.sub_delay, inter_data.sub_size, inter_data.origin_width, inter_data.origin_height); } else { Log.i ("getdata", "[text]start time:" + inter_data.sub_start + ",delay time:" + inter_data.sub_delay); @@ -95,7 +95,7 @@ class InSubApi extends SubtitleApi { Log.i ("getdata", "sub_size=0,[Bitmap]start time:" + millisec + ",delay time:" + inter_data.sub_delay); //bf_show = null; bf_show = Bitmap.createBitmap (1, 1, Config.ARGB_8888); - return new SubData (bf_show, inter_data.sub_start, inter_data.sub_delay, inter_data.sub_size); + return new SubData (bf_show, inter_data.sub_start, inter_data.sub_delay, inter_data.sub_size, 0, 0); } else { Log.i ("getdata", "sub_size=0,[text]start time:" + inter_data.sub_start + ",delay time:" + inter_data.sub_delay); diff --git a/src/com/subtitleparser/subtypes/RawData.java b/src/com/subtitleparser/subtypes/RawData.java index 41b0938..2118b8c 100755..100644 --- a/src/com/subtitleparser/subtypes/RawData.java +++ b/src/com/subtitleparser/subtypes/RawData.java @@ -12,8 +12,8 @@ public class RawData { public RawData (int[] data, int t, int w, int h, int delay, String st) { // ([BILjava/lang/String;)V rawdata = data; type = t; width = w; height = h; sub_delay = delay; codec = st; subtitlestring = null; } - public RawData (int[] data, int t, int w, int h, int size, int start, int delay, String st) { // ([BILjava/lang/String;)V - rawdata = data; type = t; width = w; height = h; sub_size = size; sub_start = start; sub_delay = delay; codec = st; subtitlestring = null; + public RawData (int[] data, int t, int w, int h, int o_w, int o_h, int size, int start, int delay, String st) { // ([BILjava/lang/String;)V + rawdata = data; type = t; width = w; height = h; origin_width=o_w; origin_height=o_h; sub_size = size; sub_start = start; sub_delay = delay; codec = st; subtitlestring = null; } public RawData(byte[] data,int t,int size,int start,int delay,String st){ @@ -44,6 +44,8 @@ public class RawData { int type; int width; int height; + int origin_width; + int origin_height; int sub_size; int sub_start; //ms int sub_delay; //ms diff --git a/src/com/subtitleview/SubtitleView.java b/src/com/subtitleview/SubtitleView.java index ba160dd..4e7af78 100644 --- a/src/com/subtitleview/SubtitleView.java +++ b/src/com/subtitleview/SubtitleView.java @@ -86,6 +86,10 @@ public class SubtitleView extends FrameLayout { hmax = maxH; } + public void setImgSubRatio(float ratio) { + wscale = hscale = ratio; + } + public void setTextColor (int color) { if (mTextView != null) { mTextView.setTextColor (color); @@ -122,8 +126,6 @@ public class SubtitleView extends FrameLayout { public void clear() { data = null; SubManager.getinstance().clear(); - wscale = 1.000f; - hscale = 1.000f; this.removeAllViews(); this.requestLayout(); } @@ -222,7 +224,7 @@ public class SubtitleView extends FrameLayout { if (data != null) { if (data.subSize() > 0) { if (data.gettype() == 1) { - evaluteScale (data.getSubBitmap() ); + //evaluteScale (data.getSubBitmap() ); Bitmap inter_bitmap = creatBitmapByScale (data.getSubBitmap(), wscale, hscale, wmax, hmax); if ( (inter_bitmap != null) && (mImageView != null) ) { mImageView.setImageBitmap (inter_bitmap); @@ -253,7 +255,7 @@ public class SubtitleView extends FrameLayout { stopOsdTimeout(); if (data != null) { if (data.gettype() == 1) { - evaluteScale (data.getSubBitmap() ); + //evaluteScale (data.getSubBitmap() ); Bitmap inter_bitmap = creatBitmapByScale (data.getSubBitmap(), wscale, hscale, wmax, hmax); if ( (inter_bitmap != null) && (mImageView != null) ) { mImageView.setImageBitmap (inter_bitmap); @@ -533,6 +535,8 @@ public class SubtitleView extends FrameLayout { dataPgsAShowed = false; dataPgsBShowed = false; resetForSeek = false; + wscale = 1.000f; + hscale = 1.000f; SubManager.getinstance().closeSubtitle(); } @@ -564,4 +568,18 @@ public class SubtitleView extends FrameLayout { public SubtitleApi getSubtitleFile() { return SubManager.getinstance().getSubtitleFile(); } + + public int getOriginW() { + if (data != null) { + return data.getOriginW(); + } + return 0; + } + + public int getOriginH() { + if (data != null) { + return data.getOriginH(); + } + return 0; + } } |