Skip to content

Commit

Permalink
refactoring ComponentType into own class
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBerendsen committed Aug 17, 2024
1 parent 78862a2 commit c052771
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
*
* http://www.digitalekabeltelevisie.nl/dvb_inspector
*
* This code is Copyright 2009-2024 by Eric Berendsen ([email protected])
*
* This file is part of DVB Inspector.
*
* DVB Inspector is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DVB Inspector is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DVB Inspector. If not, see <http://www.gnu.org/licenses/>.
*
* The author requests that he be notified of any application, applet, or
* other binary that makes use of this code, but that's more out of curiosity
* than anything and is not required.
*
*/
package nl.digitalekabeltelevisie.data.mpeg;

public enum ComponentType {
AC3("Dolby Audio (AC3)"),
E_AC3("Enhanced Dolby Audio (AC3)"),
VBI("VBI Data"),
TELETEXT("Teletext"),
DVB_SUBTITLING("DVB subtitling"),
AIT("Application Information Table (AIT)"),
RCT("Related Content Table (RCT)"),
T2MI("T2-MI"),
TTML("TTML subtitling"),
AC4("Dolby AC-4 Audio"),
SMPTE2038("SMPTE 2038");

private final String description;

ComponentType(String description) {
this.description = description;
}

public String getDescription() {
return description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* http://www.digitalekabeltelevisie.nl/dvb_inspector
*
* This code is Copyright 2009-2023 by Eric Berendsen ([email protected])
* This code is Copyright 2009-2024 by Eric Berendsen ([email protected])
*
* This file is part of DVB Inspector.
*
Expand Down Expand Up @@ -82,30 +82,6 @@
*
*/
public class TransportStream implements TreeNode{

public enum ComponentType{
AC3("Dolby Audio (AC3)"),
E_AC3("Enhanced Dolby Audio (AC3)"),
VBI("VBI Data"),
TELETEXT("Teletext"),
DVB_SUBTITLING("DVB subtitling"),
AIT("Application Information Table (AIT)"),
RCT("Related Content Table (RCT)"),
T2MI("T2-MI"),
TTML("TTML subtitling"),
AC4("Dolby AC-4 Audio"),
SMPTE2038("SMPTE 2038");

private final String description;

ComponentType(String description){
this.description = description;
}

public String getDescription() {
return description;
}
}


/**
Expand Down
58 changes: 27 additions & 31 deletions src/main/java/nl/digitalekabeltelevisie/data/mpeg/psi/PMTs.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import javax.swing.tree.DefaultMutableTreeNode;

import nl.digitalekabeltelevisie.controller.KVP;
import nl.digitalekabeltelevisie.data.mpeg.ComponentType;
import nl.digitalekabeltelevisie.data.mpeg.PSI;
import nl.digitalekabeltelevisie.data.mpeg.TransportStream.ComponentType;
import nl.digitalekabeltelevisie.data.mpeg.descriptors.ApplicationSignallingDescriptor;
import nl.digitalekabeltelevisie.data.mpeg.descriptors.ISO639LanguageDescriptor;
import nl.digitalekabeltelevisie.data.mpeg.descriptors.StreamIdentifierDescriptor;
Expand All @@ -65,49 +65,49 @@
public class PMTs extends AbstractPSITabel implements Iterable<PMTsection []>{


public PMTs(final PSI parentPSI) {
public PMTs(PSI parentPSI) {
super(parentPSI);

}

private Map<Integer, PMTsection []> pmts = new HashMap<>();
private final Map<Integer, PMTsection []> pmts = new HashMap<>();

public void update(final PMTsection section){
public void update(PMTsection section){

final int programNumber = section.getProgramNumber();
int programNumber = section.getProgramNumber();
PMTsection[] sections = pmts.computeIfAbsent(programNumber, k -> new PMTsection[section.getSectionLastNumber() + 1]);

if(sections[section.getSectionNumber()]==null){
sections[section.getSectionNumber()] = section;
}else{
final TableSection last = sections[section.getSectionNumber()];
TableSection last = sections[section.getSectionNumber()];
updateSectionVersion(section, last);
}
}

public DefaultMutableTreeNode getJTreeNode(final int modus) {
public DefaultMutableTreeNode getJTreeNode(int modus) {

final DefaultMutableTreeNode t = new DefaultMutableTreeNode(new KVP("PMTs"));
final TreeSet<Integer> s = new TreeSet<>(pmts.keySet());
DefaultMutableTreeNode t = new DefaultMutableTreeNode(new KVP("PMTs"));
Iterable<Integer> serviceIds = new TreeSet<>(pmts.keySet());

for (Integer programNumber : s) {
final PMTsection[] sections = pmts.get(programNumber);
for (Integer programNumber : serviceIds) {
PMTsection[] sections = pmts.get(programNumber);
KVP kvp = new KVP("program", programNumber, getParentPSI().getSdt().getServiceNameForActualTransportStream(programNumber));
kvp.addTableSource(() -> getTableForProgram(programNumber),"Components");
final DefaultMutableTreeNode n = new DefaultMutableTreeNode(kvp);
for (final PMTsection pmtSection : sections) {
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(kvp);
for (PMTsection pmtSection : sections) {
if (pmtSection != null) {
if (Utils.simpleModus(modus)) {
// keep it simple
n.add(new DefaultMutableTreeNode(new KVP("PCR_PID", pmtSection.getPcrPid(), null)));
addListJTree(n, pmtSection.getDescriptorList(), modus, "program_info");
addListJTree(n, pmtSection.getComponentenList(), modus, "components");
treeNode.add(new DefaultMutableTreeNode(new KVP("PCR_PID", pmtSection.getPcrPid(), null)));
addListJTree(treeNode, pmtSection.getDescriptorList(), modus, "program_info");
addListJTree(treeNode, pmtSection.getComponentenList(), modus, "components");
} else { // show all details
addSectionVersionsToJTree(n, pmtSection, modus);
addSectionVersionsToJTree(treeNode, pmtSection, modus);
}
}
}
t.add(n);
t.add(treeNode);

}
return t;
Expand All @@ -120,9 +120,9 @@ static TableHeader<PMTsection, Component> buildPmtTableHeader() {

addOptionalRowColumn("stream type", Component::getStreamtype, StreamTypeTableCellRenderer.class).
addOptionalRowColumn("usage",
c -> determineComponentType(c.getComponentDescriptorList()).
component -> determineComponentType(component.getComponentDescriptorList()).
map(ComponentType::getDescription).
orElse(getStreamTypeShortString(c.getStreamtype())),
orElse(getStreamTypeShortString(component.getStreamtype())),
String.class).
addOptionalRowColumn("elementary PID", Component::getElementaryPID, Integer.class).

Expand All @@ -148,7 +148,7 @@ static TableHeader<PMTsection, Component> buildPmtTableHeader() {
ISO639LanguageDescriptor.class,
iso -> iso.getLanguageList().
stream().
map(l->getAudioTypeString(l.getAudioType())).
map(language->getAudioTypeString(language.getAudioType())).
collect(Collectors.toList())),
String.class,
"iso").
Expand Down Expand Up @@ -214,7 +214,7 @@ private TableModel getTableForProgram(int programNumber) {
FlexTableModel<PMTsection,Component> tableModel = new FlexTableModel<>(buildPmtTableHeader());
PMTsection[] sections = pmts.get(programNumber);

for (final PMTsection pmtSection : sections) {
for (PMTsection pmtSection : sections) {
if(pmtSection!= null){
tableModel.addData(pmtSection, pmtSection.getComponentenList());
}
Expand All @@ -224,8 +224,8 @@ private TableModel getTableForProgram(int programNumber) {
return tableModel;
}

public int getPmtPID(final int programNumber){
final PMTsection [] sections = pmts.get(programNumber);
public int getPmtPID(int programNumber){
PMTsection [] sections = pmts.get(programNumber);
for (PMTsection section : sections) {
if(section!= null){
return section.getParentPID().getPid();
Expand All @@ -235,13 +235,13 @@ public int getPmtPID(final int programNumber){
}

public List<PMTsection>findPMTsFromComponentPID(int pid){
ArrayList<PMTsection> result = new ArrayList<>();
List<PMTsection> result = new ArrayList<>();
for(PMTsection[] pmtArray: pmts.values()){
PMTsection p = pmtArray[0];
for(Component component:p.getComponentenList()){
if(component.getElementaryPID()==pid){
result.add(p);
break; // every PMT is included once, even if more components wold point to same PID (which is illegal)
break; // every PMT is included once, even if more components would point to same PID (which is illegal)
}
}
}
Expand All @@ -250,7 +250,7 @@ public int getPmtPID(final int programNumber){

// PMT is always one section per program

public PMTsection getPmt(final int programNumber){
public PMTsection getPmt(int programNumber){
return pmts.get(programNumber)[0];
}

Expand All @@ -262,9 +262,5 @@ public Map<Integer, PMTsection[]> getPmts() {
return pmts;
}

public void setPmts(final Map<Integer, PMTsection[]> pmts) {
this.pmts = pmts;
}


}

0 comments on commit c052771

Please sign in to comment.