Thursday, April 21, 2016

[Discuss-gnuradio] stream_mux tag propagation

#!/usr/bin/env python2

from gnuradio import gr
from gnuradio import blocks
import pmt

class test_mux_stream(gr.top_block):
def __init__(self):
gr.top_block.__init__(self)
self.tb = gr.top_block()

src_data_a = 10*[1,1]
src_data_b = 10*[2,2,2]
#expected_result = 10*[1,1,2,2,2,]

src_a = blocks.vector_source_f(src_data_a)
src_b = blocks.vector_source_f(src_data_b)
tag_stream_a = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, 2, 'packet_len_a')
tag_stream_b = blocks.stream_to_tagged_stream(gr.sizeof_float, 1, 3, 'packet_len_b')

mux = blocks.stream_mux(gr.sizeof_float, (2, 3))
dst = blocks.vector_sink_f()

self.tb.connect(src_a, tag_stream_a)
self.tb.connect(src_b, tag_stream_b)
self.tb.connect(tag_stream_a, (mux,0))
self.tb.connect(tag_stream_b, (mux,1))
self.tb.connect(mux, dst)
self.tb.run()

print(dst.data())

# check the tags
tags = dst.tags()
for tag in tags:
print("Key: " +pmt.to_python(tag.key)
+" Value: " +str(pmt.to_python(tag.value))
+" Offset: " +str(tag.offset) )

if __name__ == '__main__':
try:
test_mux_stream().run()
except [[KeyboardInterrupt]]:
pass
Hi all,

I stumbled across the stream_mux tag propagation. In my understanding, tags are associated with one item and should be associated with the same item after processing, if possible. The stream_mux block however does not propagate tags like that:

Say we mux two tagged streams A and B, while A has packet_len_a=2 and B packet_len_b=3.

A: a1 a2 a1 a2 a1 …
---^-----^-----^--- Tag packet_len_a=2
B: b1 b2 b3 b1 b2 …
---^--------^------ Tag packet_len_b=3

packet_len tags are associated with a1 / b1 (denoted with ^).
When muxed with the scheme (2, 3), the muxed stream looks like that:

a1 a2 b1 b2 b3 a1 a2 b1 …
^-----^-----^-----^------ Tag packet_len_a=2
^--------^--------^------ Tag packet_len_b=3

The tags got associated to different items! "packet_len=2" is associated with every second item, "packet_len=3" with every third item, instead of a1 / b1.

I would assume a correct tag propagation to look like this:
a1 a2 b1 b2 b3 a1 a2 b1 …
^--------------^--------- Tag packet_len_a=2
------^--------------^--- Tag packet_len_b=3

Is that a bug in stream_mux? It means that the streams cannot be demuxed by looking at the tags.

A basic python flowgraph is attached, it prints tags and their offsets after stream_mux processing.

No comments:

Post a Comment