001/*
002 * Copyright (C) 2015 Zhang Rui <bbcallen@gmail.com>
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.baidu.cloud.media.player.misc;
018
019import com.baidu.cloud.media.player.BDCloudMediaMeta;
020
021import android.text.TextUtils;
022
023public class BDCloudTrackInfo implements ITrackInfo {
024    private int mTrackType = MEDIA_TRACK_TYPE_UNKNOWN;
025    private BDCloudMediaMeta.BDCloudStreamMeta mStreamMeta;
026
027    public BDCloudTrackInfo(BDCloudMediaMeta.BDCloudStreamMeta streamMeta) {
028        mStreamMeta = streamMeta;
029    }
030
031    public void setMediaMeta(BDCloudMediaMeta.BDCloudStreamMeta streamMeta) {
032        mStreamMeta = streamMeta;
033    }
034
035    @Override
036    public IMediaFormat getFormat() {
037        return new BDCloudMediaFormat(mStreamMeta);
038    }
039
040    @Override
041    public String getLanguage() {
042        if (mStreamMeta == null || TextUtils.isEmpty(mStreamMeta.mLanguage)) {
043            return "und";
044        }
045
046        return mStreamMeta.mLanguage;
047    }
048
049    @Override
050    public int getTrackType() {
051        return mTrackType;
052    }
053
054    public void setTrackType(int trackType) {
055        mTrackType = trackType;
056    }
057
058    @Override
059    public String toString() {
060        return getClass().getSimpleName() + '{' + getInfoInline() + "}";
061    }
062
063    @Override
064    public String getInfoInline() {
065        StringBuilder out = new StringBuilder(128);
066        switch (mTrackType) {
067            case MEDIA_TRACK_TYPE_VIDEO:
068                out.append("VIDEO");
069                out.append(", ");
070                out.append(mStreamMeta.getCodecShortNameInline());
071                out.append(", ");
072                out.append(mStreamMeta.getBitrateInline());
073                out.append(", ");
074                out.append(mStreamMeta.getResolutionInline());
075                break;
076            case MEDIA_TRACK_TYPE_AUDIO:
077                out.append("AUDIO");
078                out.append(", ");
079                out.append(mStreamMeta.getCodecShortNameInline());
080                out.append(", ");
081                out.append(mStreamMeta.getBitrateInline());
082                out.append(", ");
083                out.append(mStreamMeta.getSampleRateInline());
084                break;
085            case MEDIA_TRACK_TYPE_TIMEDTEXT:
086                out.append("TIMEDTEXT");
087                break;
088            case MEDIA_TRACK_TYPE_SUBTITLE:
089                out.append("SUBTITLE");
090                break;
091            default:
092                out.append("UNKNOWN");
093                break;
094        }
095        return out.toString();
096    }
097}